From f7c96856f90f4fcd53bc3c166736a53e9c25d729 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Fri, 29 Mar 2019 14:19:14 +0100 Subject: util: improve error property inspection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Matteo Collina --- lib/internal/util/inspect.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib/internal/util/inspect.js') 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]; } -- cgit v1.2.3