Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions front_end/panels/console/ConsoleViewMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -989,28 +989,33 @@ export class ConsoleViewMessage implements ConsoleViewportElement {
// The Exceptiondetails include script IDs for stack frames, which allows more accurate
// linking.
const formatErrorStack =
async(errorObj: SDK.RemoteObject.RemoteObject, includeCausedByPrefix: boolean): Promise<void> => {
async(errorObj: SDK.RemoteObject.RemoteObject, includeCausedByPrefix = false): Promise<void> => {
const error = SDK.RemoteObject.RemoteError.objectAsError(errorObj);
const [details, cause] = await Promise.all([error.exceptionDetails(), error.cause()]);
const errorElementType = includeCausedByPrefix ? 'div' : 'span';
let errorElement = this.tryFormatAsError(error.errorStack, details, errorElementType);
let errorElement = this.tryFormatAsError(error.errorStack, details);
if (!errorElement) {
errorElement = document.createElement(errorElementType);
errorElement = document.createElement('span');
errorElement.append(this.linkifyStringAsFragment(error.errorStack));
}

if (includeCausedByPrefix) {
errorElement.prepend('Caused by: ');
const causeElement = document.createElement('div');
causeElement.append('Caused by: ', errorElement);
result.appendChild(causeElement);
} else {
result.appendChild(errorElement);
}
result.appendChild(errorElement);

if (cause && cause.subtype === 'error') {
await formatErrorStack(cause, /* includeCausedByPrefix */ true);
} else if (cause && cause.type === 'string') {
result.append(`Caused by: ${cause.value}`);
const stringCauseElement = document.createElement('div');
stringCauseElement.append(`Caused by: ${cause.value}`);
result.append(stringCauseElement);
}
};

this.#formatErrorStackPromiseForTest = formatErrorStack(output, /* includeCausedByPrefix */ false);
this.#formatErrorStackPromiseForTest = formatErrorStack(output);

return result;
}
Expand Down Expand Up @@ -1752,8 +1757,8 @@ export class ConsoleViewMessage implements ConsoleViewportElement {
}

private tryFormatAsError(
string: string, exceptionDetails?: Protocol.Runtime.ExceptionDetails,
formattedResultType: 'div'|'span' = 'span'): HTMLElement|null {
string: string, exceptionDetails?: Protocol.Runtime.ExceptionDetails
): HTMLElement|null {
const runtimeModel = this.message.runtimeModel();
if (!runtimeModel) {
return null;
Expand All @@ -1773,7 +1778,7 @@ export class ConsoleViewMessage implements ConsoleViewportElement {
}

const debuggerModel = runtimeModel.debuggerModel();
const formattedResult = document.createElement(formattedResultType);
const formattedResult = document.createElement('span');

for (let i = 0; i < linkInfos.length; ++i) {
const newline = i < linkInfos.length - 1 ? '\n' : '';
Expand Down
Loading