diff --git a/src/extension.ts b/src/extension.ts index 2bef804..4377496 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,16 +6,16 @@ import { } from "./commands"; const DART_MODE = { language: "dart", scheme: "file" }; - function activate(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.commands.registerCommand( "widgetbook-generator.generate.directory", - generateWidgetbookEntriesForDirectory + (uri: vscode.Uri) => + runCatching(() => generateWidgetbookEntriesForDirectory(uri)) ), vscode.commands.registerCommand( "widgetbook-generator.generate.widget", - generateWidgetbookEntryForWidgetInScope + () => runCatching(() => generateWidgetbookEntryForWidgetInScope()) ), vscode.languages.registerCodeActionsProvider( DART_MODE, @@ -24,4 +24,28 @@ function activate(context: vscode.ExtensionContext) { ); } +async function runCatching(callback: () => Promise) { + const createIssueText = "Create issue"; + + try { + await callback(); + } catch (error) { + vscode.window + .showErrorMessage( + `Failed to execute action. Error: ${error}. ` + + `Please create an issue in extension's repository with minimal reproducible example.`, + createIssueText + ) + .then((selected) => { + if (selected === createIssueText) { + vscode.env.openExternal( + vscode.Uri.parse( + "https://github.com/leancodepl/widgetbook-entries-generator/issues" + ) + ); + } + }); + } +} + export { activate };