`error.stack` is not updated when `childProcess.destroy(error)` is called (due to Node.js bug)
ehmicky opened this issue · comments
ehmicky commented
When childProcess.destroy(error)
is called, the error rejected by Execa has a correct message
, but not a correct stack
.
The following works well:
const childProcess = execa('echo', {reject: false})
childProcess.stdout.destroy()
const {message, stack} = await childProcess
console.log('MESSAGE')
console.log(message)
console.log('\nSTACK')
console.log(stack)
MESSAGE
Command failed with ERR_STREAM_PREMATURE_CLOSE: echo
Premature close
STACK
Error [ERR_STREAM_PREMATURE_CLOSE]: Command failed with ERR_STREAM_PREMATURE_CLOSE: echo
Premature close
at Socket.onclose (node:internal/streams/end-of-stream:154:30)
at Socket.emit (node:events:527:35)
at Pipe.<anonymous> (node:net:337:12)
But the following stack lacks Command failed with ...
:
const childProcess = execa('echo', {reject: false})
childProcess.stdout.destroy(new Error('example'))
const {message, stack} = await childProcess
console.log('MESSAGE')
console.log(message)
console.log('\nSTACK')
console.log(stack)
MESSAGE
Command failed with exit code 0: echo
example
STACK
Error: example
at file:///home/ether/code/execa/a.js:4:29
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:34:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
This is due to a bug in Node.js, which is related to a quirky behavior with V8 that might or might not be a bug.