Skip to content

Commit 3a718ee

Browse files
committed
Include the full stack in error log messages
Ensure we only show the truncated error message in the popup. This will help with debugging.
1 parent 5401244 commit 3a718ee

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

extensions/ql-vscode/src/commandRunner.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@ export function commandRunner(
126126
showAndLogWarningMessage(errorMessage);
127127
}
128128
} else {
129-
showAndLogErrorMessage(errorMessage);
129+
// Include the full stack in the error log only.
130+
const fullMessage = e.stack
131+
? `${errorMessage}\n${e.stack}`
132+
: errorMessage;
133+
showAndLogErrorMessage(errorMessage, {
134+
fullMessage
135+
});
130136
}
131137
return undefined;
132138
}
@@ -165,7 +171,13 @@ export function commandRunnerWithProgress<R>(
165171
showAndLogWarningMessage(errorMessage);
166172
}
167173
} else {
168-
showAndLogErrorMessage(errorMessage);
174+
// Include the full stack in the error log only.
175+
const fullMessage = e.stack
176+
? `${errorMessage}\n${e.stack}`
177+
: errorMessage;
178+
showAndLogErrorMessage(errorMessage, {
179+
fullMessage
180+
});
169181
}
170182
return undefined;
171183
}

extensions/ql-vscode/src/helpers.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ import { logger } from './logging';
1616
* @param message The message to show.
1717
* @param options.outputLogger The output logger that will receive the message
1818
* @param options.items A set of items that will be rendered as actions in the message.
19+
* @param options.fullMessage An alternate message that is added to the log, but not displayed
20+
* in the popup. This is useful for adding extra detail to the logs
21+
* that would be too noisy for the popup.
1922
*
2023
* @return A promise that resolves to the selected item or undefined when being dismissed.
2124
*/
2225
export async function showAndLogErrorMessage(message: string, {
2326
outputLogger = logger,
24-
items = [] as string[]
27+
items = [] as string[],
28+
fullMessage = undefined as (string | undefined)
2529
} = {}): Promise<string | undefined> {
26-
return internalShowAndLog(message, items, outputLogger, Window.showErrorMessage);
30+
return internalShowAndLog(message, items, outputLogger, Window.showErrorMessage, fullMessage);
2731
}
2832
/**
2933
* Show a warning message and log it to the console
@@ -58,10 +62,15 @@ export async function showAndLogInformationMessage(message: string, {
5862

5963
type ShowMessageFn = (message: string, ...items: string[]) => Thenable<string | undefined>;
6064

61-
async function internalShowAndLog(message: string, items: string[], outputLogger = logger,
62-
fn: ShowMessageFn): Promise<string | undefined> {
65+
async function internalShowAndLog(
66+
message: string,
67+
items: string[],
68+
outputLogger = logger,
69+
fn: ShowMessageFn,
70+
fullMessage?: string
71+
): Promise<string | undefined> {
6372
const label = 'Show Log';
64-
outputLogger.log(message);
73+
outputLogger.log(fullMessage || message);
6574
const result = await fn(message, label, ...items);
6675
if (result === label) {
6776
outputLogger.show();

0 commit comments

Comments
 (0)