-
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.
process: reduce the number of internal frames in async stack trace
Previously, we call the JS land `runNextTicks` implementation immediately from JS land after evaluating the main module or the input, so these synchronous JS call frames would show up in the stack trace of the async errors, which can be confusing. This patch moves those calls into C++ so that more of these internal scheduler implementation details can be hidden and the users can see a cleaner a cleaner async JS stack trace. PR-URL: #27392 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
- Loading branch information
1 parent
dc510fb
commit d00014e
Showing
22 changed files
with
233 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
async function one() { | ||
throw new Error('test'); | ||
} | ||
|
||
async function breaker() { | ||
return true; | ||
} | ||
|
||
async function stack() { | ||
await breaker(); | ||
} | ||
|
||
async function two() { | ||
await stack(); | ||
await one(); | ||
} | ||
async function three() { | ||
await two(); | ||
} | ||
|
||
async function four() { | ||
await three(); | ||
} | ||
|
||
module.exports = four; |
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,39 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const { spawnSync } = require('child_process'); | ||
|
||
const four = require('../common/fixtures') | ||
.readSync('async-error.js') | ||
.toString() | ||
.split('\n') | ||
.slice(2, -2) | ||
.join('\n'); | ||
|
||
const main = `${four} | ||
async function main() { | ||
try { | ||
await four(); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
main(); | ||
`; | ||
|
||
// --eval CJS | ||
{ | ||
const child = spawnSync(process.execPath, [ | ||
'-e', | ||
main | ||
], { | ||
env: { ...process.env } | ||
}); | ||
|
||
if (child.status !== 0) { | ||
console.error(child.stderr.toString()); | ||
} | ||
console.error(child.stdout.toString()); | ||
} |
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,6 @@ | ||
Error: test | ||
at one ([eval]:2:9) | ||
at two ([eval]:15:9) | ||
at async three ([eval]:18:3) | ||
at async four ([eval]:22:3) | ||
at async main ([eval]:28:5) |
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,42 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const { spawnSync } = require('child_process'); | ||
|
||
const four = require('../common/fixtures') | ||
.readSync('async-error.js') | ||
.toString() | ||
.split('\n') | ||
.slice(2, -2) | ||
.join('\n'); | ||
|
||
const main = `${four} | ||
async function main() { | ||
try { | ||
await four(); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
main(); | ||
`; | ||
|
||
// --eval ESM | ||
{ | ||
const child = spawnSync(process.execPath, [ | ||
'--experimental-modules', | ||
'--input-type', | ||
'module', | ||
'-e', | ||
main | ||
], { | ||
env: { ...process.env } | ||
}); | ||
|
||
if (child.status !== 0) { | ||
console.error(child.stderr.toString()); | ||
} | ||
console.error(child.stdout.toString()); | ||
} |
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,7 @@ | ||
Error: test | ||
at one (eval:1:2:9) | ||
at two (eval:1:15:9) | ||
at processTicksAndRejections (internal/process/task_queues.js:*:*) | ||
at async three (eval:1:18:3) | ||
at async four (eval:1:22:3) | ||
at async main (eval:1:28:5) |
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,13 @@ | ||
'use strict'; | ||
require('../common'); | ||
const four = require('../fixtures/async-error'); | ||
|
||
async function main() { | ||
try { | ||
await four(); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
|
||
queueMicrotask(main); |
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,6 @@ | ||
Error: test | ||
at one (*fixtures*async-error.js:4:9) | ||
at two (*fixtures*async-error.js:17:9) | ||
at async three (*fixtures*async-error.js:20:3) | ||
at async four (*fixtures*async-error.js:24:3) | ||
at async main (*message*async_error_microtask_main.js:7:5) |
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,13 @@ | ||
'use strict'; | ||
require('../common'); | ||
const four = require('../fixtures/async-error'); | ||
|
||
async function main() { | ||
try { | ||
await four(); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
|
||
process.nextTick(main); |
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,7 @@ | ||
Error: test | ||
at one (*fixtures*async-error.js:4:9) | ||
at two (*fixtures*async-error.js:17:9) | ||
at processTicksAndRejections (internal/process/task_queues.js:*:*) | ||
at async three (*fixtures*async-error.js:20:3) | ||
at async four (*fixtures*async-error.js:24:3) | ||
at async main (*message*async_error_nexttick_main.js:7:5) |
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,14 @@ | ||
// Flags: --experimental-modules | ||
/* eslint-disable node-core/required-modules */ | ||
import '../common/index.mjs'; | ||
import four from '../fixtures/async-error.js'; | ||
|
||
async function main() { | ||
try { | ||
await four(); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
|
||
main(); |
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,7 @@ | ||
(node:*) ExperimentalWarning: The ESM module loader is experimental. | ||
Error: test | ||
at one (*fixtures*async-error.js:4:9) | ||
at two (*fixtures*async-error.js:17:9) | ||
at async three (*fixtures*async-error.js:20:3) | ||
at async four (*fixtures*async-error.js:24:3) | ||
at async main (*message*async_error_sync_esm.mjs:8:5) |
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,13 @@ | ||
'use strict'; | ||
require('../common'); | ||
const four = require('../fixtures/async-error'); | ||
|
||
async function main() { | ||
try { | ||
await four(); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
|
||
main(); |
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,6 @@ | ||
Error: test | ||
at one (*fixtures*async-error.js:4:9) | ||
at two (*fixtures*async-error.js:17:9) | ||
at async three (*fixtures*async-error.js:20:3) | ||
at async four (*fixtures*async-error.js:24:3) | ||
at async main (*message*async_error_sync_main.js:7:5) |
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