Skip to content

Commit f09b027

Browse files
ryancoletjfontaine
authored andcommitted
child_process: add path to spawn ENOENT Error
Add a file property to the ENOENT Error returned from ChildProcess's spawn function. Signed-off-by: Timothy J Fontaine <tjfontaine@gmail.com>
1 parent 01c2a67 commit f09b027

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

‎lib/child_process.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,7 @@ function ChildProcess() {
10101010
this.signalCode = null;
10111011
this.exitCode = null;
10121012
this.killed = false;
1013+
this.spawnfile = null;
10131014

10141015
this._handle = new Process();
10151016
this._handle.owner = this;
@@ -1025,7 +1026,8 @@ function ChildProcess() {
10251026
//
10261027
// - spawn failures are reported with exitCode < 0
10271028
//
1028-
var err = (exitCode < 0) ? errnoException(exitCode, 'spawn') : null;
1029+
var syscall = self.spawnfile ? 'spawn ' + self.spawnfile : 'spawn';
1030+
var err = (exitCode < 0) ? errnoException(exitCode, syscall) : null;
10291031

10301032
if (signalCode) {
10311033
self.signalCode = signalCode;
@@ -1041,6 +1043,9 @@ function ChildProcess() {
10411043
self._handle = null;
10421044

10431045
if (exitCode < 0) {
1046+
if (self.spawnfile)
1047+
err.path = self.spawnfile;
1048+
10441049
self.emit('error', err);
10451050
} else {
10461051
self.emit('exit', self.exitCode, self.signalCode);
@@ -1102,6 +1107,8 @@ ChildProcess.prototype.spawn = function(options) {
11021107
options.envPairs.push('NODE_CHANNEL_FD=' + ipcFd);
11031108
}
11041109

1110+
this.spawnfile = options.file;
1111+
11051112
var err = this._handle.spawn(options);
11061113

11071114
if (err == uv.UV_ENOENT) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
var fs = require('fs');
23+
var spawn = require('child_process').spawn;
24+
var assert = require('assert');
25+
26+
var errors = 0;
27+
28+
var enoentPath = 'foo123';
29+
assert.equal(fs.existsSync(enoentPath), false);
30+
31+
var enoentChild = spawn(enoentPath);
32+
enoentChild.on('error', function (err) {
33+
assert.equal(err.path, enoentPath);
34+
errors++;
35+
});
36+
37+
process.on('exit', function() {
38+
assert.equal(1, errors);
39+
});

0 commit comments

Comments
 (0)