extensionSystem: Improve error formatting
This exposes the formatted error with stack trace and proper location of SyntaxErrors over the bus, instead of just the message. <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3041> Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3041>
This commit is contained in:

committed by
Florian Müllner

parent
1692004b6b
commit
71befc5ff7
@ -14,8 +14,8 @@ function formatExceptionStack(error) {
|
||||
return `\n\nStack trace:\n${indentedStack}`;
|
||||
}
|
||||
|
||||
function formatExceptionWithCause(error, seenCauses) {
|
||||
let fmt = formatExceptionStack(error);
|
||||
function formatExceptionWithCause(error, seenCauses, showStack) {
|
||||
let fmt = showStack ? formatExceptionStack(error) : '';
|
||||
|
||||
const {cause} = error;
|
||||
if (!cause)
|
||||
@ -39,9 +39,12 @@ function formatExceptionWithCause(error, seenCauses) {
|
||||
* location where a SyntaxError was thrown into account.
|
||||
*
|
||||
* @param {Error} error The error to format
|
||||
* @param {object} options Formatting options
|
||||
* @param {boolean} options.showStack Whether to show the stack trace (default
|
||||
* true)
|
||||
* @returns {string} The formatted string
|
||||
*/
|
||||
export function formatError(error) {
|
||||
export function formatError(error, {showStack = true} = {}) {
|
||||
try {
|
||||
let fmt = `${error}`;
|
||||
if (error === null || typeof error !== 'object')
|
||||
@ -49,12 +52,13 @@ export function formatError(error) {
|
||||
|
||||
if (error instanceof SyntaxError) {
|
||||
fmt += formatSyntaxErrorLocation(error);
|
||||
fmt += formatExceptionStack(error);
|
||||
if (showStack)
|
||||
fmt += formatExceptionStack(error);
|
||||
return fmt;
|
||||
}
|
||||
|
||||
const seenCauses = new Set([error]);
|
||||
fmt += formatExceptionWithCause(error, seenCauses);
|
||||
fmt += formatExceptionWithCause(error, seenCauses, showStack);
|
||||
return fmt;
|
||||
} catch (e) {
|
||||
return `(could not display error: ${e})`;
|
||||
|
Reference in New Issue
Block a user