Conversation
|
This is still a draft, but it is good enough to have a look and get some feedback. I need to do some more manual testing as well as add some unit tests. |
| Uri, | ||
| ProgressOptions, | ||
| ProgressLocation, | ||
| CancellationToken, |
There was a problem hiding this comment.
This file is mostly about disentangling all the error handling and progress reporting.
28c710c to
81d51bb
Compare
f40f349 to
59ef027
Compare
| KeyType.DefinitionQuery, | ||
| (src, _dest) => src === uriString | ||
| ); | ||
| return await withProgress({ |
There was a problem hiding this comment.
Here and elsewhere: This return await can just be a return right? Otherwise we'll await the outcome of the promise, then wrap up the result in a second promise anyway, and return that.
There was a problem hiding this comment.
It's redundant. I can remove. Though, I don't think the behaviour is any different due to hoisting of promises. It is essentially this snippet:
async function a() {
throw new Error('1')
}
async function b1() {
return await a()
}
async function b2() {
return a()
}
async function c() {
try {
await b1()
} catch (e) {
console.log(e)
}
try {
await b2()
} catch (e) {
console.log(e)
}
}
c()Both errors are properly captured.
| * If there is no progress monitor, then only extra command arguments are passed in. | ||
| * | ||
| * @param commandId The ID of the command to register. | ||
| * @param task The task to run. If passing taskOptions, then this task must be a `ProgressTask`. |
There was a problem hiding this comment.
| * @param task The task to run. If passing taskOptions, then this task must be a `ProgressTask`. | |
| * @param task The task to run. If passing `progressOptions`, then this task must be a `ProgressTask`. |
| } else if (e instanceof Error) { | ||
| showAndLogErrorMessage(e.message); | ||
| } else { | ||
| throw e; |
There was a problem hiding this comment.
Should we always handle this (show and log) to avoid uncaught promise rejections at the top level?
There was a problem hiding this comment.
Our code should always be throwing errors. If a non-error is thrown, then that is just...strange and something unexpected is happening. I don't feel strongly about this since it shouldn't happen. I can remove.
There was a problem hiding this comment.
Need to handle the case where e.message is undefined.
| task: ProgressTask<R> | NoProgressTask, | ||
| progressOptions?: ProgressOptions |
There was a problem hiding this comment.
I wonder whether it would be safer to split this into two variants:
- accept
task: ProgressTask<R>andprogressOptions - accept
task: NoProgressTaskand noprogressOptions.
That way it's obvious whenever we attempt to write new code that uses this.
There was a problem hiding this comment.
So, commandRunner and commandRunnerWithProgress? I guess this would allow us to ensure we send the proper number of arguments for each style.
There was a problem hiding this comment.
That sounds fine. I don't know whether TS overloading rules will let you have the same name with different types and arities.
There was a problem hiding this comment.
It's actually a good thing that I changed to different names. It uncovered one instance when I was calling a command handler with the wrong arguments.
59ef027 to
4ab5a03
Compare
|
Thanks for the review. I rebased and didn't address any of your comments yet. I will tomorrow. |
c44581f to
7cde605
Compare
The commandRunner wraps all vscode command registrations. It provides uniform error handling and an optional progress monitor. In general, progress monitors should only be created by the commandRunner and passed through to the locations that use it.
When a user runs multiple queries on a non-upgraded database, ensure that only one dialog appears for upgrade. This commit also migrates the upgrades.ts file to using the passed-in cancellation token and progress monitor. This ensures that cancelling a database upgrade command will also cancel out of any wrapper operations. Fixes github#534
Co-authored-by: Shati Patel <42641846+shati-patel@users.noreply.github.com>
7cde605 to
e9ed1e5
Compare
| * There are two ways to invoke the command task: with or without a progress monitor | ||
| * If progressOptions are passed in, then the command task will run with a progress monitor | ||
| * Otherwise, no progress monitor will be used. | ||
| * | ||
| * If a task is run with a progress monitor, the first two arguments to the task are always | ||
| * the progress callback, and the cancellation token. And this is followed by any extra command arguments | ||
| * (eg- selection, multiselection, ...). | ||
| * | ||
| * If there is no progress monitor, then only extra command arguments are passed in. |
There was a problem hiding this comment.
Split this across the two methods, so each documents the specific case it handles.
Split commandRunner into two functions: commandRunner and commandRunnerWithProgress. Also, take advantage of default arguments for ProgressOptions. And updates changelog.
e9ed1e5 to
ad06780
Compare
The commandRunner wraps all vscode command registrations. It provides
uniform error handling and an optional progress monitor.
In general, progress monitors should only be created by the
commandRunner and passed through to the locations that use it.
Resolves #464.
Resolves #534.
Checklist
@github/docs-content-dsphas been cc'd in all issues for UI or other user-facing changes made by this pull request.