Uh oh!
There was an error while loading. Please reload this page.
doc: child_process: clarify subprocess.pid can be undefined when ENOENT - #37014
Conversation
aduh95
commented
Jan 21, 2021
Do you want to update the test to make sure there's no regression in the future? node/test/parallel/test-child-process-spawn-error.js Lines 29 to 42 in 3df5afb |
dr-js
commented
Jan 22, 2021
Sure, I'll try update the test. |
@aduh95 Upon adding the test, I found the
Should I add more detailed behavior description to the doc and update test for async and sync spawn, The test code for this: [test.js][()=>testSpawn('with invalid command',['non-exist-command']),()=>testSpawn('with invalid command and `shell: true`',['non-exist-command',{shell: true}]),()=>testSpawn('with invalid cwd',['node',{cwd: './non/exist/cwd/path/'}]),()=>testSpawn('invalid cwd and `shell: true`',['node',{cwd: './non/exist/cwd/path/',shell: true}]),()=>testSpawnSync('with invalid command',['non-exist-command']),()=>testSpawnSync('with invalid command and `shell: true`',['non-exist-command',{shell: true}]),()=>testSpawnSync('with invalid cwd',['node',{cwd: './non/exist/cwd/path/'}]),()=>testSpawnSync('invalid cwd and `shell: true`',['node',{cwd: './non/exist/cwd/path/',shell: true}])].forEach((testFunc,index)=>setTimeout(testFunc,index*200))constformatError=(error)=>error&&error.message// const formatError = (error) => error && error.stack // for more detailconsttestSpawn=(title='',spawnArgs='')=>{console.log(`\n== test spawn ${title} ==`)const{ spawn }=require('child_process')constsubProcess=spawn(...spawnArgs)subProcess.on('error',(error)=>console.warn('- "error" event:',formatError(error)))// mute Unhandled "error" event or the test will exitconsole.log('- pid:',subProcess.pid,'exitCode:',subProcess.exitCode)process.nextTick(()=>console.log('- nextTick pid:',subProcess.pid,'exitCode:',subProcess.exitCode))setTimeout(()=>console.log('- after 100ms pid:',subProcess.pid,'exitCode:',subProcess.exitCode),100)}consttestSpawnSync=(title='',spawnArgs='')=>{console.log(`\n== test spawnSync ${title} ==`)const{ spawnSync }=require('child_process')constoutcome=spawnSync(...spawnArgs)// NOTE: not a `subProcess`console.log('- pid:',outcome.pid,'status',outcome.status)console.log('- error',formatError(outcome.error))}And the output: [v15.6.0 linux x64][v15.6.0 win32 x64] |
aduh95
commented
Jan 22, 2021
Hum that's weird indeed, that might be a bug with |
dr-js
commented
Jan 22, 2021
@aduh95 Sure, so in this PR I'll add docs & test checks for And I'll open another Issue with above test to discuss sync spawn pid behavior, and maybe a PR to add test to |
Uh oh!
There was an error while loading. Please reload this page.
9933250 to
fd5748bCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Trott
commented
Jan 31, 2021
LGTM with doc updates. @nodejs/documentation @nodejs/child_process |
ec48ec2 to
61f86f3Comparenodejs-github-bot
commented
Feb 19, 2021
From the code `nodejs@8` and up should behave the same:
github.com/nodejs/node/blame/v8.17.0/lib/internal/child_process.js#L290
And a short test snippet:
```js
const { spawn } = require('child_process')
const subProcess = spawn('non-exist-command')
subProcess.on('error', (error) =>
console.warn('mute Unhandled "error" event:', error))
console.log('- pid:', subProcess.pid)
process.nextTick(() => console.log('- after error emit'))
console.log('== end of test ==')
```
Note: the sync spawn result `pid` currently do not follow this pattern.
Co-authored-by: Rich Trott <rtrott@gmail.com>
PR-URL: nodejs#37014
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>Note: this only add checks for async spawn, as the sync spawn do not return a `subProcess`. PR-URL: nodejs#37014 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
61f86f3 to
1e0cfa3Compareaduh95
commented
Feb 22, 2021
Landed in 574590d...1e0cfa3 |
From the code `nodejs@8` and up should behave the same:
github.com/nodejs/node/blame/v8.17.0/lib/internal/child_process.js#L290
And a short test snippet:
```js
const { spawn } = require('child_process')
const subProcess = spawn('non-exist-command')
subProcess.on('error', (error) =>
console.warn('mute Unhandled "error" event:', error))
console.log('- pid:', subProcess.pid)
process.nextTick(() => console.log('- after error emit'))
console.log('== end of test ==')
```
Note: the sync spawn result `pid` currently do not follow this pattern.
Co-authored-by: Rich Trott <rtrott@gmail.com>
PR-URL: #37014
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>Note: this only add checks for async spawn, as the sync spawn do not return a `subProcess`. PR-URL: #37014 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
From the code `nodejs@8` and up should behave the same:
github.com/nodejs/node/blame/v8.17.0/lib/internal/child_process.js#L290
And a short test snippet:
```js
const { spawn } = require('child_process')
const subProcess = spawn('non-exist-command')
subProcess.on('error', (error) =>
console.warn('mute Unhandled "error" event:', error))
console.log('- pid:', subProcess.pid)
process.nextTick(() => console.log('- after error emit'))
console.log('== end of test ==')
```
Note: the sync spawn result `pid` currently do not follow this pattern.
Co-authored-by: Rich Trott <rtrott@gmail.com>
PR-URL: #37014
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>Note: this only add checks for async spawn, as the sync spawn do not return a `subProcess`. PR-URL: #37014 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
From the code
nodejs@8and up should behave the same: https://github.com/nodejs/node/blame/v8.17.0/lib/internal/child_process.js#L290-L316And a short test snippet: