mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
util: fix inspected stack indentation
Error stacks and multiline error messages were not correct indented. This is fixed by this patch. PR-URL: https://github.com/nodejs/node/pull/20802 Refs: https://github.com/nodejs/node/issues/20253 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
parent
8de83725ac
commit
e852289802
@ -590,6 +590,11 @@ function formatValue(ctx, value, recurseTimes) {
|
||||
if (base.indexOf('\n at') === -1) {
|
||||
base = `[${base}]`;
|
||||
}
|
||||
// The message and the stack have to be indented as well!
|
||||
if (ctx.indentationLvl !== 0) {
|
||||
const indentation = ' '.repeat(ctx.indentationLvl);
|
||||
base = formatError(value).replace(/\n/g, `\n${indentation}`);
|
||||
}
|
||||
if (keyLength === 0)
|
||||
return base;
|
||||
} else if (isAnyArrayBuffer(value)) {
|
||||
|
12
test/message/util_inspect_error.js
Normal file
12
test/message/util_inspect_error.js
Normal file
@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const util = require('util');
|
||||
|
||||
const err = new Error('foo\nbar');
|
||||
|
||||
console.log(util.inspect({ err, nested: { err } }, { compact: true }));
|
||||
console.log(util.inspect({ err, nested: { err } }, { compact: false }));
|
||||
|
||||
err.foo = 'bar';
|
||||
console.log(util.inspect(err, { compact: true, breakLength: 5 }));
|
63
test/message/util_inspect_error.out
Normal file
63
test/message/util_inspect_error.out
Normal file
@ -0,0 +1,63 @@
|
||||
{ err:
|
||||
Error: foo
|
||||
bar
|
||||
at *util_inspect_error*
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
nested:
|
||||
{ err:
|
||||
Error: foo
|
||||
bar
|
||||
at *util_inspect_error*
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at * } }
|
||||
{
|
||||
err: Error: foo
|
||||
bar
|
||||
at *util_inspect_error*
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *,
|
||||
nested: {
|
||||
err: Error: foo
|
||||
bar
|
||||
at *util_inspect_error*
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
}
|
||||
}
|
||||
{ Error: foo
|
||||
bar
|
||||
at *util_inspect_error*
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
at *
|
||||
foo: 'bar' }
|
Loading…
Reference in New Issue
Block a user