Skip to content

Commit 5a853a0

Browse files
devsnekBridgeAR
authored andcommitted
Revert "util: change util.inspect depth default"
This reverts commit ac7450a. This fully reverts the changes to util.inspect depth. It has caused breakage in logging to existing apps, and even something as simple as `console.log(require)` will cause >1m freezes. I've heard nothing but negative feedback (seriously not a single person has expressed anything positive about this change) and personally i find this change extremely annoying.
1 parent 5b78d2c commit 5a853a0

File tree

6 files changed

+27
-60
lines changed

6 files changed

+27
-60
lines changed

doc/api/util.md

+5-16
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ changes:
419419
* `depth` {number} Specifies the number of times to recurse while formatting
420420
the `object`. This is useful for inspecting large complicated objects. To
421421
make it recurse up to the maximum call stack size pass `Infinity` or `null`.
422-
**Default:** `20`.
422+
**Default:** `2`.
423423
* `colors` {boolean} If `true`, the output will be styled with ANSI color
424424
codes. Colors are customizable, see [Customizing `util.inspect` colors][].
425425
**Default:** `false`.
@@ -476,23 +476,12 @@ util.inspect(new Bar()); // 'Bar {}'
476476
util.inspect(baz); // '[foo] {}'
477477
```
478478

479-
The following example limits the inspected output of the `paths` property:
479+
The following example inspects all properties of the `util` object:
480480

481481
```js
482482
const util = require('util');
483483

484-
console.log(util.inspect(module, { depth: 0 }));
485-
// Instead of showing all entries in `paths` `[Array]` is used to limit the
486-
// output for readability:
487-
488-
// Module {
489-
// id: '<repl>',
490-
// exports: {},
491-
// parent: undefined,
492-
// filename: null,
493-
// loaded: false,
494-
// children: [],
495-
// paths: [Array] }
484+
console.log(util.inspect(util, { showHidden: true, depth: null }));
496485
```
497486

498487
The following example highlights the difference with the `compact` option:
@@ -508,7 +497,7 @@ const o = {
508497
'foo']], 4],
509498
b: new Map([['za', 1], ['zb', 'test']])
510499
};
511-
console.log(util.inspect(o, { compact: true, breakLength: 80 }));
500+
console.log(util.inspect(o, { compact: true, depth: 5, breakLength: 80 }));
512501

513502
// This will print
514503

@@ -522,7 +511,7 @@ console.log(util.inspect(o, { compact: true, breakLength: 80 }));
522511
// b: Map { 'za' => 1, 'zb' => 'test' } }
523512

524513
// Setting `compact` to false changes the output to be more reader friendly.
525-
console.log(util.inspect(o, { compact: false, breakLength: 80 }));
514+
console.log(util.inspect(o, { compact: false, depth: 5, breakLength: 80 }));
526515

527516
// {
528517
// a: [

lib/internal/util/inspect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const hasOwnProperty = uncurryThis(Object.prototype.hasOwnProperty);
9292

9393
const inspectDefaultOptions = Object.seal({
9494
showHidden: false,
95-
depth: 20,
95+
depth: 2,
9696
colors: false,
9797
customInspect: true,
9898
showProxy: false,

lib/repl.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ function hasOwnProperty(obj, prop) {
130130
// and it can be overridden by custom print functions, such as `probe` or
131131
// `eyes.js`.
132132
const writer = exports.writer = (obj) => util.inspect(obj, writer.options);
133-
writer.options = Object.assign({},
134-
util.inspect.defaultOptions,
135-
{ showProxy: true, depth: 2 });
133+
writer.options =
134+
Object.assign({}, util.inspect.defaultOptions, { showProxy: true });
136135

137136
exports._builtinLibs = builtinLibs;
138137

test/parallel/test-stream-buffer-list.js

-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require('../common');
44
const assert = require('assert');
55
const BufferList = require('internal/streams/buffer_list');
6-
const util = require('util');
76

87
// Test empty buffer list.
98
const emptyList = new BufferList();
@@ -31,11 +30,3 @@ assert.strictEqual(list.join(','), 'foo');
3130
const shifted = list.shift();
3231
assert.strictEqual(shifted, buf);
3332
assert.deepStrictEqual(list, new BufferList());
34-
35-
const tmp = util.inspect.defaultOptions.colors;
36-
util.inspect.defaultOptions = { colors: true };
37-
assert.strictEqual(
38-
util.inspect(list),
39-
'BufferList { head: \u001b[1mnull\u001b[22m, tail: \u001b[1mnull\u001b[22m,' +
40-
' length: \u001b[33m0\u001b[39m }');
41-
util.inspect.defaultOptions = { colors: tmp };

test/parallel/test-util-inspect-proxy.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,13 @@ const expected1 = 'Proxy [ {}, {} ]';
5050
const expected2 = 'Proxy [ Proxy [ {}, {} ], {} ]';
5151
const expected3 = 'Proxy [ Proxy [ Proxy [ {}, {} ], {} ], Proxy [ {}, {} ] ]';
5252
const expected4 = 'Proxy [ Proxy [ {}, {} ], Proxy [ Proxy [ {}, {} ], {} ] ]';
53-
const expected5 = 'Proxy [ Proxy [ Proxy [ Proxy [ {}, {} ], {} ],' +
53+
const expected5 = 'Proxy [ Proxy [ Proxy [ Proxy [Array], {} ],' +
5454
' Proxy [ {}, {} ] ],\n Proxy [ Proxy [ {}, {} ]' +
55-
', Proxy [ Proxy [ {}, {} ], {} ] ] ]';
56-
const expected6 = 'Proxy [ Proxy [ Proxy [ Proxy [ Proxy [ {}, {} ], {} ], ' +
57-
'Proxy [ {}, {} ] ],\n' +
58-
' Proxy [ Proxy [ {}, {} ], ' +
59-
'Proxy [ Proxy [ {}, {} ], {} ] ] ],\n' +
60-
' Proxy [ Proxy [ Proxy [ Proxy [ {}, {} ], {} ], ' +
61-
'Proxy [ {}, {} ] ],\n' +
62-
' Proxy [ Proxy [ {}, {} ], ' +
63-
'Proxy [ Proxy [ {}, {} ], {} ] ] ] ]';
55+
', Proxy [ Proxy [Array], {} ] ] ]';
56+
const expected6 = 'Proxy [ Proxy [ Proxy [ Proxy [Array], Proxy [Array]' +
57+
' ],\n Proxy [ Proxy [Array], Proxy [Array] ] ],\n' +
58+
' Proxy [ Proxy [ Proxy [Array], Proxy [Array] ],\n' +
59+
' Proxy [ Proxy [Array], Proxy [Array] ] ] ]';
6460
assert.strictEqual(
6561
util.inspect(proxy1, { showProxy: true, depth: null }),
6662
expected1);

test/parallel/test-util-inspect.js

+13-21
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ assert.strictEqual(util.inspect({ a: 1, b: 2 }), '{ a: 1, b: 2 }');
7171
assert.strictEqual(util.inspect({ 'a': {} }), '{ a: {} }');
7272
assert.strictEqual(util.inspect({ 'a': { 'b': 2 } }), '{ a: { b: 2 } }');
7373
assert.strictEqual(util.inspect({ 'a': { 'b': { 'c': { 'd': 2 } } } }),
74-
'{ a: { b: { c: { d: 2 } } } }');
74+
'{ a: { b: { c: [Object] } } }');
7575
assert.strictEqual(
7676
util.inspect({ 'a': { 'b': { 'c': { 'd': 2 } } } }, false, null),
7777
'{ a: { b: { c: { d: 2 } } } }');
@@ -110,7 +110,7 @@ assert.strictEqual(util.inspect((new JSStream())._externalStream),
110110
assert.strictEqual(util.inspect({ a: regexp }, false, 0), '{ a: /regexp/ }');
111111
}
112112

113-
assert(!/Object/.test(
113+
assert(/Object/.test(
114114
util.inspect({ a: { a: { a: { a: {} } } } }, undefined, undefined, true)
115115
));
116116
assert(!/Object/.test(
@@ -1055,15 +1055,15 @@ if (typeof Symbol !== 'undefined') {
10551055
// Empty and circular before depth.
10561056
{
10571057
const arr = [[[[]]]];
1058-
assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ [] ] ] ]');
1058+
assert.strictEqual(util.inspect(arr), '[ [ [ [] ] ] ]');
10591059
arr[0][0][0][0] = [];
1060-
assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ [Array] ] ] ]');
1060+
assert.strictEqual(util.inspect(arr), '[ [ [ [Array] ] ] ]');
10611061
arr[0][0][0] = {};
1062-
assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ {} ] ] ]');
1062+
assert.strictEqual(util.inspect(arr), '[ [ [ {} ] ] ]');
10631063
arr[0][0][0] = { a: 2 };
1064-
assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ [Object] ] ] ]');
1064+
assert.strictEqual(util.inspect(arr), '[ [ [ [Object] ] ] ]');
10651065
arr[0][0][0] = arr;
1066-
assert.strictEqual(util.inspect(arr, { depth: 2 }), '[ [ [ [Circular] ] ] ]');
1066+
assert.strictEqual(util.inspect(arr), '[ [ [ [Circular] ] ] ]');
10671067
}
10681068

10691069
// Corner cases.
@@ -1160,10 +1160,10 @@ if (typeof Symbol !== 'undefined') {
11601160
assert(!/1 more item/.test(util.inspect(arr)));
11611161
util.inspect.defaultOptions.maxArrayLength = oldOptions.maxArrayLength;
11621162
assert(/1 more item/.test(util.inspect(arr)));
1163-
util.inspect.defaultOptions.depth = 2;
1164-
assert(/Object/.test(util.inspect(obj)));
1165-
util.inspect.defaultOptions.depth = oldOptions.depth;
1163+
util.inspect.defaultOptions.depth = null;
11661164
assert(!/Object/.test(util.inspect(obj)));
1165+
util.inspect.defaultOptions.depth = oldOptions.depth;
1166+
assert(/Object/.test(util.inspect(obj)));
11671167
assert.strictEqual(
11681168
JSON.stringify(util.inspect.defaultOptions),
11691169
JSON.stringify(oldOptions)
@@ -1175,7 +1175,7 @@ if (typeof Symbol !== 'undefined') {
11751175
assert(/Object/.test(util.inspect(obj)));
11761176
util.inspect.defaultOptions = oldOptions;
11771177
assert(/1 more item/.test(util.inspect(arr)));
1178-
assert(!/Object/.test(util.inspect(obj)));
1178+
assert(/Object/.test(util.inspect(obj)));
11791179
assert.strictEqual(
11801180
JSON.stringify(util.inspect.defaultOptions),
11811181
JSON.stringify(oldOptions)
@@ -1561,19 +1561,11 @@ util.inspect(process);
15611561
let head = list;
15621562
// A linked list of length 100k should be inspectable in some way, even though
15631563
// the real cutoff value is much lower than 100k.
1564-
for (let i = 0; i < 100000; i++) {
1564+
for (let i = 0; i < 100000; i++)
15651565
head = head.next = {};
1566-
}
1567-
1568-
const res = Array(15)
1569-
.fill(0)
1570-
.map((_, i) => `{ next:\n${' '.repeat(i + 1)}`)
1571-
.join('') +
1572-
'{ next: { next: { next: { next: { next: { next:' +
1573-
' [Object] } } } } } } } } } } } } } } } } } } } } }';
15741566
assert.strictEqual(
15751567
util.inspect(list),
1576-
res
1568+
'{ next: { next: { next: [Object] } } }'
15771569
);
15781570
const longList = util.inspect(list, { depth: Infinity });
15791571
const match = longList.match(/next/g);

0 commit comments

Comments
 (0)