Skip to content

spawn error doesn't utilize event handlers #990

Closed
@ORESoftware

Description

@ORESoftware

Nodejs version 6.10.x

I have this:

const file = path.resolve(__dirname + '/foo.js');
const  n = cp.spawn(file, []);  // EACCES error is thrown here

n.once('error', function () {
  // this does not get hit !!
});

so it seems like I should do this instead (but the try/catch seems unfortunate):

let n;

try{
  n = cp.spawn(file, []);  //  EACCES error is thrown here
}
catch(err){
  return cb(err);
}

n.once('error', function () {
  // this does not get hit !!
});

seems like the 'error' handler should be given the chance to capture error, instead of necessitating a try/catch, am I doing something wrong?

Perhaps because Node core does not even create the n child process object, that seems like an implementation "mistake".


HOW TO REPLICATE:

Create a file without executable permissions, then try to execute it directly:

#!/usr/bin/env bash
touch my-non-executable-file.js
./my-non-executable-file.js

so that would be something like:

const k = cp.spawn('/foo/bar/my-non-executable-file.js');

the above should throw an error, instead of using k.on('error', fn)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions