Move duplicated error handling into showResolvableLocation

This commit is contained in:
Robert
2023-08-08 14:40:05 +01:00
parent daf389a5ed
commit f4d6990c1f
2 changed files with 14 additions and 27 deletions

View File

@@ -230,21 +230,7 @@ export class DataExtensionsEditorView extends AbstractWebview<
protected async jumpToUsage(
location: ResolvableLocationValue,
): Promise<void> {
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<void> {

View File

@@ -97,8 +97,19 @@ export function tryResolveLocation(
export async function showResolvableLocation(
loc: ResolvableLocationValue,
databaseItem: DatabaseItem,
logger: Logger,
): Promise<void> {
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);
}
}