Skip to content

Commit a96168d

Browse files
committed
Open query server logger for query errors
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.
1 parent eec72e0 commit a96168d

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

extensions/ql-vscode/src/commandRunner.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ export function commandRunner(
160160
export function commandRunnerWithProgress<R>(
161161
commandId: string,
162162
task: ProgressTask<R>,
163-
progressOptions: Partial<ProgressOptions>
163+
progressOptions: Partial<ProgressOptions>,
164+
outputLogger = logger
164165
): Disposable {
165166
return commands.registerCommand(commandId, async (...args: any[]) => {
166167
const startTime = Date.now();
@@ -177,16 +178,17 @@ export function commandRunnerWithProgress<R>(
177178
if (e instanceof UserCancellationException) {
178179
// User has cancelled this action manually
179180
if (e.silent) {
180-
void logger.log(errorMessage);
181+
void outputLogger.log(errorMessage);
181182
} else {
182-
void showAndLogWarningMessage(errorMessage);
183+
void showAndLogWarningMessage(errorMessage, { outputLogger });
183184
}
184185
} else {
185186
// Include the full stack in the error log only.
186187
const fullMessage = e.stack
187188
? `${errorMessage}\n${e.stack}`
188189
: errorMessage;
189190
void showAndLogErrorMessage(errorMessage, {
191+
outputLogger,
190192
fullMessage
191193
});
192194
}

extensions/ql-vscode/src/extension.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ async function activateWithInstalledDistribution(
539539
// Note we must update the query history view after showing results as the
540540
// display and sorting might depend on the number of results
541541
} catch (e) {
542+
e.message = `Error running query: ${e.message}`;
542543
item.failureReason = e.message;
543544
throw e;
544545
} finally {
@@ -639,7 +640,10 @@ async function activateWithInstalledDistribution(
639640
{
640641
title: 'Running query',
641642
cancellable: true
642-
}
643+
},
644+
645+
// Open the query server logger on error since that's usually where the interesting errors appear.
646+
queryServerLogger
643647
)
644648
);
645649
interface DatabaseQuickPickItem extends QuickPickItem {
@@ -771,7 +775,11 @@ async function activateWithInstalledDistribution(
771775
{
772776
title: 'Running queries',
773777
cancellable: true
774-
})
778+
},
779+
780+
// Open the query server logger on error since that's usually where the interesting errors appear.
781+
queryServerLogger
782+
)
775783
);
776784
ctx.subscriptions.push(
777785
commandRunnerWithProgress(
@@ -784,7 +792,10 @@ async function activateWithInstalledDistribution(
784792
{
785793
title: 'Running query',
786794
cancellable: true
787-
})
795+
},
796+
// Open the query server logger on error since that's usually where the interesting errors appear.
797+
queryServerLogger
798+
)
788799
);
789800

790801
ctx.subscriptions.push(
@@ -799,7 +810,11 @@ async function activateWithInstalledDistribution(
799810
{
800811
title: 'Running query',
801812
cancellable: true
802-
})
813+
},
814+
815+
// Open the query server logger on error since that's usually where the interesting errors appear.
816+
queryServerLogger
817+
)
803818
);
804819

805820
ctx.subscriptions.push(
@@ -810,7 +825,10 @@ async function activateWithInstalledDistribution(
810825
displayQuickQuery(ctx, cliServer, databaseUI, progress, token),
811826
{
812827
title: 'Run Quick Query'
813-
}
828+
},
829+
830+
// Open the query server logger on error since that's usually where the interesting errors appear.
831+
queryServerLogger
814832
)
815833
);
816834

0 commit comments

Comments
 (0)