-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: expose default prepareStackTrace
Expose the default prepareStackTrace implementation as `Error.prepareStackTrace` so that userland can chain up formatting of stack traces with built-in source maps support. PR-URL: #50827 Fixes: #50733 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
- Loading branch information
1 parent
3310095
commit 291265c
Showing
11 changed files
with
148 additions
and
56 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
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
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
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
34 changes: 34 additions & 0 deletions
34
test/fixtures/source-map/output/source_map_prepare_stack_trace.js
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,34 @@ | ||
// Flags: --enable-source-maps | ||
|
||
'use strict'; | ||
require('../../../common'); | ||
const assert = require('assert'); | ||
Error.stackTraceLimit = 5; | ||
|
||
assert.strictEqual(typeof Error.prepareStackTrace, 'function'); | ||
const defaultPrepareStackTrace = Error.prepareStackTrace; | ||
Error.prepareStackTrace = (error, trace) => { | ||
trace = trace.filter(it => { | ||
return it.getFunctionName() !== 'functionC'; | ||
}); | ||
return defaultPrepareStackTrace(error, trace); | ||
}; | ||
|
||
try { | ||
require('../enclosing-call-site-min.js'); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
|
||
delete require.cache[require | ||
.resolve('../enclosing-call-site-min.js')]; | ||
|
||
// Disable | ||
process.setSourceMapsEnabled(false); | ||
assert.strictEqual(process.sourceMapsEnabled, false); | ||
|
||
try { | ||
require('../enclosing-call-site-min.js'); | ||
} catch (e) { | ||
console.log(e); | ||
} |
10 changes: 10 additions & 0 deletions
10
test/fixtures/source-map/output/source_map_prepare_stack_trace.snapshot
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,10 @@ | ||
Error: an error! | ||
at functionD (*enclosing-call-site.js:16:17) | ||
at functionB (*enclosing-call-site.js:6:3) | ||
at functionA (*enclosing-call-site.js:2:3) | ||
at Object.<anonymous> (*enclosing-call-site.js:24:3) | ||
Error: an error! | ||
at functionD (*enclosing-call-site-min.js:1:156) | ||
at functionB (*enclosing-call-site-min.js:1:60) | ||
at functionA (*enclosing-call-site-min.js:1:26) | ||
at Object.<anonymous> (*enclosing-call-site-min.js:1:199) |
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