-
Notifications
You must be signed in to change notification settings - Fork 30k
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>
- Loading branch information
Showing
3 changed files
with
161 additions
and
13 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,21 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
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 }); | ||
|
||
console.log(error); | ||
console.log(cause3); | ||
console.log(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,68 @@ | ||
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 * | ||
} | ||
} | ||
} |