Skip to content

Commit

Permalink
Open query server logger for query errors
Browse files Browse the repository at this point in the history
Because errors when running queries tend to have better explanations
in the query server log instead of the extension log, by default open
the query server log for query errors.
  • Loading branch information
aeisenberg committed Feb 18, 2022
1 parent eec72e0 commit a96168d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
8 changes: 5 additions & 3 deletions extensions/ql-vscode/src/commandRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ export function commandRunner(
export function commandRunnerWithProgress<R>(
commandId: string,
task: ProgressTask<R>,
progressOptions: Partial<ProgressOptions>
progressOptions: Partial<ProgressOptions>,
outputLogger = logger
): Disposable {
return commands.registerCommand(commandId, async (...args: any[]) => {
const startTime = Date.now();
Expand All @@ -177,16 +178,17 @@ export function commandRunnerWithProgress<R>(
if (e instanceof UserCancellationException) {
// User has cancelled this action manually
if (e.silent) {
void logger.log(errorMessage);
void outputLogger.log(errorMessage);
} else {
void showAndLogWarningMessage(errorMessage);
void showAndLogWarningMessage(errorMessage, { outputLogger });
}
} else {
// Include the full stack in the error log only.
const fullMessage = e.stack
? `${errorMessage}\n${e.stack}`
: errorMessage;
void showAndLogErrorMessage(errorMessage, {
outputLogger,
fullMessage
});
}
Expand Down
28 changes: 23 additions & 5 deletions extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ async function activateWithInstalledDistribution(
// Note we must update the query history view after showing results as the
// display and sorting might depend on the number of results
} catch (e) {
e.message = `Error running query: ${e.message}`;
item.failureReason = e.message;
throw e;
} finally {
Expand Down Expand Up @@ -639,7 +640,10 @@ async function activateWithInstalledDistribution(
{
title: 'Running query',
cancellable: true
}
},

// Open the query server logger on error since that's usually where the interesting errors appear.
queryServerLogger
)
);
interface DatabaseQuickPickItem extends QuickPickItem {
Expand Down Expand Up @@ -771,7 +775,11 @@ async function activateWithInstalledDistribution(
{
title: 'Running queries',
cancellable: true
})
},

// Open the query server logger on error since that's usually where the interesting errors appear.
queryServerLogger
)
);
ctx.subscriptions.push(
commandRunnerWithProgress(
Expand All @@ -784,7 +792,10 @@ async function activateWithInstalledDistribution(
{
title: 'Running query',
cancellable: true
})
},
// Open the query server logger on error since that's usually where the interesting errors appear.
queryServerLogger
)
);

ctx.subscriptions.push(
Expand All @@ -799,7 +810,11 @@ async function activateWithInstalledDistribution(
{
title: 'Running query',
cancellable: true
})
},

// Open the query server logger on error since that's usually where the interesting errors appear.
queryServerLogger
)
);

ctx.subscriptions.push(
Expand All @@ -810,7 +825,10 @@ async function activateWithInstalledDistribution(
displayQuickQuery(ctx, cliServer, databaseUI, progress, token),
{
title: 'Run Quick Query'
}
},

// Open the query server logger on error since that's usually where the interesting errors appear.
queryServerLogger
)
);

Expand Down

0 comments on commit a96168d

Please sign in to comment.