From f4d6990c1f634d57dcae6b0afb77058ab87e532d Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 8 Aug 2023 14:40:05 +0100 Subject: [PATCH] Move duplicated error handling into showResolvableLocation --- .../data-extensions-editor-view.ts | 16 +----------- .../databases/local-databases/locations.ts | 25 ++++++++++--------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/extensions/ql-vscode/src/data-extensions-editor/data-extensions-editor-view.ts b/extensions/ql-vscode/src/data-extensions-editor/data-extensions-editor-view.ts index a99a0145d..9ed5d3a10 100644 --- a/extensions/ql-vscode/src/data-extensions-editor/data-extensions-editor-view.ts +++ b/extensions/ql-vscode/src/data-extensions-editor/data-extensions-editor-view.ts @@ -230,21 +230,7 @@ export class DataExtensionsEditorView extends AbstractWebview< protected async jumpToUsage( location: ResolvableLocationValue, ): Promise { - try { - await showResolvableLocation(location, this.databaseItem); - } catch (e) { - if (e instanceof Error) { - if (e.message.match(/File not found/)) { - void window.showErrorMessage( - "Original file of this result is not in the database's source archive.", - ); - } else { - void this.app.logger.log(`Unable to handleMsgFromView: ${e.message}`); - } - } else { - void this.app.logger.log(`Unable to handleMsgFromView: ${e}`); - } - } + await showResolvableLocation(location, this.databaseItem, this.app.logger); } protected async loadExistingModeledMethods(): Promise { diff --git a/extensions/ql-vscode/src/databases/local-databases/locations.ts b/extensions/ql-vscode/src/databases/local-databases/locations.ts index 5654b01b1..9625cca3d 100644 --- a/extensions/ql-vscode/src/databases/local-databases/locations.ts +++ b/extensions/ql-vscode/src/databases/local-databases/locations.ts @@ -97,8 +97,19 @@ export function tryResolveLocation( export async function showResolvableLocation( loc: ResolvableLocationValue, databaseItem: DatabaseItem, + logger: Logger, ): Promise { - await showLocation(tryResolveLocation(loc, databaseItem)); + try { + await showLocation(tryResolveLocation(loc, databaseItem)); + } catch (e) { + if (e instanceof Error && e.message.match(/File not found/)) { + void Window.showErrorMessage( + "Original file of this result is not in the database's source archive.", + ); + } else { + void logger.log(`Unable to jump to location: ${getErrorMessage(e)}`); + } + } } export async function showLocation(location?: Location) { @@ -146,16 +157,6 @@ export async function jumpToLocation( ) { const databaseItem = databaseManager.findDatabaseItem(Uri.parse(databaseUri)); if (databaseItem !== undefined) { - try { - await showResolvableLocation(loc, databaseItem); - } catch (e) { - if (e instanceof Error && e.message.match(/File not found/)) { - void Window.showErrorMessage( - "Original file of this result is not in the database's source archive.", - ); - } else { - void logger.log(`Unable to jump to location: ${getErrorMessage(e)}`); - } - } + await showResolvableLocation(loc, databaseItem, logger); } }