Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
util: fix inspected stack indentation
Error stacks and multiline error messages were not correct indented.
This is fixed by this patch.
  • Loading branch information
BridgeAR committed May 20, 2018
commit 96b303c75abc8809d521f5917ee41377c6037c23
5 changes: 5 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
12 changes: 12 additions & 0 deletions test/message/util_inspect_error.js
Original file line number Diff line number Diff line change
@@ -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 changes: 63 additions & 0 deletions test/message/util_inspect_error.out
Original file line number Diff line number Diff line change
@@ -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' }