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.
This commit is contained in:
@@ -22,6 +22,14 @@ export class RedactableError extends Error {
|
||||
.join("");
|
||||
}
|
||||
|
||||
public get fullMessageWithStack(): string {
|
||||
if (!this.stack) {
|
||||
return this.fullMessage;
|
||||
}
|
||||
|
||||
return `${this.fullMessage}\n${this.stack}`;
|
||||
}
|
||||
|
||||
public get redactedMessage(): string {
|
||||
return this.strings
|
||||
.map((s, i) => s + (this.hasValue(i) ? this.getRedactedValue(i) : ""))
|
||||
|
||||
@@ -112,5 +112,5 @@ export async function showAndLogExceptionWithTelemetry(
|
||||
options: ShowAndLogExceptionOptions = {},
|
||||
): Promise<void> {
|
||||
telemetry?.sendError(error, options.extraTelemetryProperties);
|
||||
return showAndLogErrorMessage(logger, error.fullMessage, options);
|
||||
return showAndLogErrorMessage(logger, error.fullMessageWithStack, options);
|
||||
}
|
||||
|
||||
@@ -6,11 +6,7 @@ import {
|
||||
showAndLogExceptionWithTelemetry,
|
||||
} from "../logging";
|
||||
import { extLogger } from "../logging/vscode";
|
||||
import {
|
||||
asError,
|
||||
getErrorMessage,
|
||||
getErrorStack,
|
||||
} from "../../common/helpers-pure";
|
||||
import { asError, getErrorMessage } from "../../common/helpers-pure";
|
||||
import { redactableError } from "../../common/errors";
|
||||
import { UserCancellationException } from "./progress";
|
||||
import { telemetryListener } from "./telemetry";
|
||||
@@ -66,10 +62,7 @@ export function registerCommandWithErrorHandling(
|
||||
}
|
||||
} else {
|
||||
// Include the full stack in the error log only.
|
||||
const errorStack = getErrorStack(e);
|
||||
const fullMessage = errorStack
|
||||
? `${errorMessage.fullMessage}\n${errorStack}`
|
||||
: errorMessage.fullMessage;
|
||||
const fullMessage = errorMessage.fullMessageWithStack;
|
||||
void showAndLogExceptionWithTelemetry(logger, telemetry, errorMessage, {
|
||||
fullMessage,
|
||||
extraTelemetryProperties: {
|
||||
|
||||
@@ -1170,10 +1170,7 @@ function addUnhandledRejectionListener() {
|
||||
const message = redactableError(
|
||||
asError(error),
|
||||
)`Unhandled error: ${getErrorMessage(error)}`;
|
||||
const stack = getErrorStack(error);
|
||||
const fullMessage = stack
|
||||
? `Unhandled error: ${stack}`
|
||||
: message.fullMessage;
|
||||
const fullMessage = message.fullMessageWithStack;
|
||||
|
||||
// Add a catch so that showAndLogExceptionWithTelemetry fails, we avoid
|
||||
// triggering "unhandledRejection" and avoid an infinite loop
|
||||
|
||||
@@ -441,7 +441,6 @@ export async function compileAndRunQueryAgainstDatabaseCore(
|
||||
const error = result.message
|
||||
? redactableError`${result.message}`
|
||||
: redactableError`Failed to run query`;
|
||||
void extLogger.log(error.fullMessage);
|
||||
void showAndLogExceptionWithTelemetry(
|
||||
extLogger,
|
||||
telemetryListener,
|
||||
|
||||
Reference in New Issue
Block a user