-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util: always visualize cause property in errors during inspection
While inspecting errors, always visualize the cause. That property is non-enumerable by default while being useful in general for debugging. Duplicated stack frames are hidden. Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de> PR-URL: #41002 Fixes: #40859 Fixes: #38725 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
- Loading branch information
1 parent
af9b05f
commit b15f5e4
Showing
3 changed files
with
261 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
const { inspect } = require('util'); | ||
|
||
class FoobarError extends Error { | ||
status = 'Feeling good'; | ||
} | ||
|
||
const cause1 = new TypeError('Inner error'); | ||
const cause2 = new FoobarError('Individual message', { cause: cause1 }); | ||
cause2.extraProperties = 'Yes!'; | ||
const cause3 = new Error('Stack causes', { cause: cause2 }); | ||
|
||
process.nextTick(() => { | ||
const error = new RangeError('New Stack Frames', { cause: cause2 }); | ||
const error2 = new RangeError('New Stack Frames', { cause: cause3 }); | ||
|
||
inspect.defaultOptions.colors = true; | ||
|
||
console.log(inspect(error)); | ||
console.log(inspect(cause3)); | ||
console.log(inspect(error2)); | ||
|
||
inspect.defaultOptions.colors = false; | ||
|
||
console.log(inspect(error)); | ||
console.log(inspect(cause3)); | ||
console.log(inspect(error2)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
RangeError: New Stack Frames | ||
at * | ||
*[90m at *[39m { | ||
[cause]: FoobarError: Individual message | ||
at * | ||
*[90m at *[39m | ||
*[90m ... 4 lines matching cause stack trace ...*[39m | ||
*[90m at *[39m { | ||
status: *[32m'Feeling good'*[39m, | ||
extraProperties: *[32m'Yes!'*[39m, | ||
[cause]: TypeError: Inner error | ||
at * | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
} | ||
} | ||
Error: Stack causes | ||
at * | ||
*[90m at *[39m | ||
*[90m ... 4 lines matching cause stack trace ...*[39m | ||
*[90m at *[39m { | ||
[cause]: FoobarError: Individual message | ||
at * | ||
*[90m at *[39m | ||
*[90m ... 4 lines matching cause stack trace ...*[39m | ||
*[90m at *[39m { | ||
status: *[32m'Feeling good'*[39m, | ||
extraProperties: *[32m'Yes!'*[39m, | ||
[cause]: TypeError: Inner error | ||
at * | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
} | ||
} | ||
RangeError: New Stack Frames | ||
at * | ||
*[90m at *[39m { | ||
[cause]: Error: Stack causes | ||
at * | ||
*[90m at *[39m | ||
*[90m ... 4 lines matching cause stack trace ...*[39m | ||
*[90m at *[39m { | ||
[cause]: FoobarError: Individual message | ||
at * | ||
*[90m at *[39m | ||
*[90m ... 4 lines matching cause stack trace ...*[39m | ||
*[90m at *[39m { | ||
status: *[32m'Feeling good'*[39m, | ||
extraProperties: *[32m'Yes!'*[39m, | ||
[cause]: TypeError: Inner error | ||
at * | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
*[90m at *[39m | ||
} | ||
} | ||
} | ||
RangeError: New Stack Frames | ||
at * | ||
at * { | ||
[cause]: FoobarError: Individual message | ||
at * | ||
at * | ||
... 4 lines matching cause stack trace ... | ||
at * { | ||
status: 'Feeling good', | ||
extraProperties: 'Yes!', | ||
[cause]: TypeError: Inner error | ||
at * | ||
at * | ||
at * | ||
at * | ||
at * | ||
at * | ||
at * | ||
} | ||
} | ||
Error: Stack causes | ||
at * | ||
at * | ||
... 4 lines matching cause stack trace ... | ||
at * { | ||
[cause]: FoobarError: Individual message | ||
at * | ||
at * | ||
... 4 lines matching cause stack trace ... | ||
at * | ||
status: 'Feeling good', | ||
extraProperties: 'Yes!', | ||
[cause]: TypeError: Inner error | ||
at * | ||
at * | ||
at * | ||
at * | ||
at * | ||
at * | ||
at * | ||
} | ||
} | ||
RangeError: New Stack Frames | ||
at * | ||
at * { | ||
[cause]: Error: Stack causes | ||
at * | ||
at * | ||
... 4 lines matching cause stack trace ... | ||
at * { | ||
[cause]: FoobarError: Individual message | ||
at * | ||
at * | ||
... 4 lines matching cause stack trace ... | ||
at * { | ||
status: 'Feeling good', | ||
extraProperties: 'Yes!', | ||
[cause]: TypeError: Inner error | ||
at * | ||
at * | ||
at * | ||
at * | ||
at * | ||
at * | ||
at * | ||
} | ||
} | ||
} |