summaryrefslogtreecommitdiff
path: root/lib/internal/util/inspect.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-03-29 14:19:14 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-04-03 02:31:05 +0200
commitf7c96856f90f4fcd53bc3c166736a53e9c25d729 (patch)
treeecaed30fa0431dcd89df3bfceada804ab4989aad /lib/internal/util/inspect.js
parent14b2db0145c6c8715a701458dfb6ac4ec664df6d (diff)
downloadandroid-node-v8-f7c96856f90f4fcd53bc3c166736a53e9c25d729.tar.gz
android-node-v8-f7c96856f90f4fcd53bc3c166736a53e9c25d729.tar.bz2
android-node-v8-f7c96856f90f4fcd53bc3c166736a53e9c25d729.zip
util: improve error property inspection
This makes sure that errors that contain extra properties show those properties on a separate line. PR-URL: https://github.com/nodejs/node/pull/26984 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'lib/internal/util/inspect.js')
-rw-r--r--lib/internal/util/inspect.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index 9280e2ac5f..87e53d62f6 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
@@ -1342,7 +1342,7 @@ function formatProperty(ctx, value, recurseTimes, key, type) {
return `${name}:${extra}${str}`;
}
-function isBelowBreakLength(ctx, output, start) {
+function isBelowBreakLength(ctx, output, start, base) {
// Each entry is separated by at least a comma. Thus, we start with a total
// length of at least `output.length`. In addition, some cases have a
// whitespace in-between each other that is added to the total as well.
@@ -1359,7 +1359,8 @@ function isBelowBreakLength(ctx, output, start) {
return false;
}
}
- return true;
+ // Do not line up properties on the same line if `base` contains line breaks.
+ return base === '' || !base.includes('\n');
}
function reduceToSingleString(ctx, output, base, braces, combine = false) {
@@ -1370,7 +1371,7 @@ function reduceToSingleString(ctx, output, base, braces, combine = false) {
// that may reduce `breakLength`.
const start = output.length + ctx.indentationLvl +
braces[0].length + base.length + 10;
- if (isBelowBreakLength(ctx, output, start)) {
+ if (isBelowBreakLength(ctx, output, start, base)) {
return `${base ? `${base} ` : ''}${braces[0]} ${join(output, ', ')} ` +
braces[1];
}
@@ -1382,7 +1383,7 @@ function reduceToSingleString(ctx, output, base, braces, combine = false) {
}
// Line up all entries on a single line in case the entries do not exceed
// `breakLength`.
- if (isBelowBreakLength(ctx, output, 0)) {
+ if (isBelowBreakLength(ctx, output, 0, base)) {
return `${braces[0]}${base ? ` ${base}` : ''} ${join(output, ', ')} ` +
braces[1];
}