Skip to content

Commit 78f832a

Browse files
committed
Show stack for redactable error in log
When calling for example `showAndLogExceptionWithTelemetry`, the stack trace would be sent to Application Insights, but there was no way to see the stack trace from within VS Code. This will add the stack trace to the log by returning it from `fullMessageWithStack` and using it in the appropriate places.
1 parent d20cf92 commit 78f832a

File tree

5 files changed

+12
-15
lines changed

5 files changed

+12
-15
lines changed

extensions/ql-vscode/src/common/errors.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ export class RedactableError extends Error {
2222
.join("");
2323
}
2424

25+
public get fullMessageWithStack(): string {
26+
if (!this.stack) {
27+
return this.fullMessage;
28+
}
29+
30+
return `${this.fullMessage}\n${this.stack}`;
31+
}
32+
2533
public get redactedMessage(): string {
2634
return this.strings
2735
.map((s, i) => s + (this.hasValue(i) ? this.getRedactedValue(i) : ""))

extensions/ql-vscode/src/common/logging/notifications.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,5 @@ export async function showAndLogExceptionWithTelemetry(
112112
options: ShowAndLogExceptionOptions = {},
113113
): Promise<void> {
114114
telemetry?.sendError(error, options.extraTelemetryProperties);
115-
return showAndLogErrorMessage(logger, error.fullMessage, options);
115+
return showAndLogErrorMessage(logger, error.fullMessageWithStack, options);
116116
}

extensions/ql-vscode/src/common/vscode/commands.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import {
66
showAndLogExceptionWithTelemetry,
77
} from "../logging";
88
import { extLogger } from "../logging/vscode";
9-
import {
10-
asError,
11-
getErrorMessage,
12-
getErrorStack,
13-
} from "../../common/helpers-pure";
9+
import { asError, getErrorMessage } from "../../common/helpers-pure";
1410
import { redactableError } from "../../common/errors";
1511
import { UserCancellationException } from "./progress";
1612
import { telemetryListener } from "./telemetry";
@@ -66,10 +62,7 @@ export function registerCommandWithErrorHandling(
6662
}
6763
} else {
6864
// Include the full stack in the error log only.
69-
const errorStack = getErrorStack(e);
70-
const fullMessage = errorStack
71-
? `${errorMessage.fullMessage}\n${errorStack}`
72-
: errorMessage.fullMessage;
65+
const fullMessage = errorMessage.fullMessageWithStack;
7366
void showAndLogExceptionWithTelemetry(logger, telemetry, errorMessage, {
7467
fullMessage,
7568
extraTelemetryProperties: {

extensions/ql-vscode/src/extension.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,10 +1170,7 @@ function addUnhandledRejectionListener() {
11701170
const message = redactableError(
11711171
asError(error),
11721172
)`Unhandled error: ${getErrorMessage(error)}`;
1173-
const stack = getErrorStack(error);
1174-
const fullMessage = stack
1175-
? `Unhandled error: ${stack}`
1176-
: message.fullMessage;
1173+
const fullMessage = message.fullMessageWithStack;
11771174

11781175
// Add a catch so that showAndLogExceptionWithTelemetry fails, we avoid
11791176
// triggering "unhandledRejection" and avoid an infinite loop

extensions/ql-vscode/src/query-server/legacy/run-queries.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ export async function compileAndRunQueryAgainstDatabaseCore(
441441
const error = result.message
442442
? redactableError`${result.message}`
443443
: redactableError`Failed to run query`;
444-
void extLogger.log(error.fullMessage);
445444
void showAndLogExceptionWithTelemetry(
446445
extLogger,
447446
telemetryListener,

0 commit comments

Comments
 (0)