-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework showing of generic error message #795
Merged
Merged
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2e0ba8b
add output channel into internal commands
mattseddon 85ef140
deduplicate with build dependencies function
mattseddon 9b2ab84
rework how and when we show generic error message
mattseddon 5a9bc48
duplicate external registration inside internal commands
mattseddon e9cee45
register more commands using internal commands
mattseddon 2e7db3d
register remaining commands with internal commands facade
mattseddon 2f8b70e
swap order in function signature for experiment command registration
mattseddon 6ff2cfe
show generic error and do not throw on dvc error
mattseddon 9cf6662
do not expect an error for commands that will fail because of the cli
mattseddon c7b1ed3
split commands between cli and non cli
mattseddon d685db1
Merge branch 'master' of https://github.com/iterative/vscode-dvc into…
mattseddon 2c33cc2
update test wording
mattseddon 7a61713
remove dead code
mattseddon 3f7190d
only direct user to dvc channel for cli based errors
mattseddon 71a869b
fix integration test to expect error again
mattseddon 1244b9a
let vs code handle error message for failed non-cli command
mattseddon ffefc29
do not throw inside report pass the error up
mattseddon 8387f44
split commands enums between cli and non cli
mattseddon b02bc52
remove erroneuos brackets
mattseddon 8f06b10
revert to throwing error if change of execution details fails
mattseddon 5a283bc
send the correct error event for stopping an experiment
mattseddon c57f470
Merge branch 'master' into rework-default-notifications
mattseddon 0fe2f7b
Merge branch 'master' into rework-default-notifications
mattseddon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
import { commands } from 'vscode' | ||
import { Disposable } from '../extension' | ||
import { sendTelemetryEventAndThrow, sendTelemetryEvent } from '../telemetry' | ||
import { StopWatch } from '../util/time' | ||
|
||
export enum RegisteredCommands { | ||
EXPERIMENT_APPLY = 'dvc.applyExperiment', | ||
EXPERIMENT_BRANCH = 'dvc.branchExperiment', | ||
|
@@ -46,20 +41,3 @@ export enum RegisteredCommands { | |
TRACKED_EXPLORER_COPY_FILE_PATH = 'dvc.copyFilePath', | ||
TRACKED_EXPLORER_COPY_REL_FILE_PATH = 'dvc.copyRelativeFilePath' | ||
} | ||
|
||
export const registerInstrumentedCommand = <T = string | undefined>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [F] This has been replaced by an |
||
name: RegisteredCommands, | ||
func: (arg: T) => unknown | ||
): Disposable => | ||
commands.registerCommand(name, async arg => { | ||
const stopWatch = new StopWatch() | ||
try { | ||
const res = await func(arg) | ||
sendTelemetryEvent(name, undefined, { | ||
duration: stopWatch.getElapsedTime() | ||
}) | ||
return res | ||
} catch (e: unknown) { | ||
sendTelemetryEventAndThrow(name, e as Error, stopWatch.getElapsedTime()) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
import { commands } from 'vscode' | ||
import { Disposable } from '@hediet/std/disposable' | ||
import { RegisteredCommands } from './external' | ||
import { ICli } from '../cli' | ||
import { Args } from '../cli/args' | ||
import { Config } from '../config' | ||
import { quickPickOne } from '../vscode/quickPick' | ||
import { autoRegisteredCommands as CliExecutorCommands } from '../cli/executor' | ||
import { autoRegisteredCommands as CliReaderCommands } from '../cli/reader' | ||
import { autoRegisteredCommands as CliRunnerCommands } from '../cli/runner' | ||
import { Config } from '../config' | ||
import { OutputChannel } from '../vscode/outputChannel' | ||
import { quickPickOne } from '../vscode/quickPick' | ||
import { StopWatch } from '../util/time' | ||
import { sendTelemetryEvent, sendTelemetryEventAndThrow } from '../telemetry' | ||
import { showGenericError } from '../vscode/modal' | ||
|
||
type Command = (...args: Args) => unknown | Promise<unknown> | ||
|
||
export const AvailableCommands = Object.assign( | ||
{ | ||
GET_DEFAULT_OR_PICK_PROJECT: 'getDefaultOrPickProject', | ||
GET_THEME: 'getTheme' | ||
GET_THEME: 'getTheme', | ||
REGISTER_EXTERNAL_COMMAND: 'registerExternalCommand' | ||
} as const, | ||
CliExecutorCommands, | ||
CliReaderCommands, | ||
|
@@ -24,9 +31,15 @@ export class InternalCommands { | |
public dispose = Disposable.fn() | ||
|
||
private readonly commands = new Map<string, Command>() | ||
private readonly outputChannel: OutputChannel | ||
|
||
constructor(config: Config, ...cliInteractors: ICli[]) { | ||
constructor( | ||
config: Config, | ||
outputChannel: OutputChannel, | ||
...cliInteractors: ICli[] | ||
) { | ||
cliInteractors.forEach(cli => this.autoRegisterCommands(cli)) | ||
this.outputChannel = outputChannel | ||
|
||
this.registerCommand( | ||
AvailableCommands.GET_DEFAULT_OR_PICK_PROJECT, | ||
|
@@ -65,6 +78,32 @@ export class InternalCommands { | |
this.commands.set(commandId, command) | ||
} | ||
|
||
public registerExternalCommand<T = string | undefined>( | ||
name: RegisteredCommands, | ||
func: (arg: T) => unknown | ||
): void { | ||
this.dispose.track( | ||
commands.registerCommand(name, async arg => { | ||
const stopWatch = new StopWatch() | ||
try { | ||
const res = await func(arg) | ||
sendTelemetryEvent(name, undefined, { | ||
duration: stopWatch.getElapsedTime() | ||
}) | ||
return res | ||
} catch (e: unknown) { | ||
showGenericError() | ||
this.outputChannel.show() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [F] Want to rework this part now |
||
sendTelemetryEventAndThrow( | ||
name, | ||
e as Error, | ||
stopWatch.getElapsedTime() | ||
) | ||
} | ||
}) | ||
) | ||
} | ||
|
||
private autoRegisterCommands(cli: ICli) { | ||
cli.autoRegisteredCommands.forEach((commandId: string) => { | ||
if (!this.confirmedId(commandId)) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[F] We now want to catch these errors in the same place to send an analytics error event