You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constfile=path.resolve(__dirname+'/foo.js');constn=cp.spawn(file,[]);// EACCES error is thrown heren.once('error',function(){// this does not get hit !!});
so it seems like I should do this instead (but the try/catch seems unfortunate):
letn;try{n=cp.spawn(file,[]);// EACCES error is thrown here}catch(err){returncb(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:
one can argue that n represents a child process and in this case as the process was never created, n not being fully formed makes sense.
Technically it may be possible to first compose a JS object that is going to abstract the child process that is being spawned. But a more natural way of doing this is to materialize the entity first, and then abstract the entity. (the entity here being the native process).
eh, because the child process was never "started", I can't use an 'exit' handler on the child process, which forces me to rethink my own program design. It seems like a child was started in reality, but I don't know the internals that well. I don't see why you'd ever have to put a try/catch around spawn. IMO a better design would be to always use n.on('error').
@bnoordhuis this seems like a design mistake in node core. Having to put try/catch around
this block of code defines what is runtime error and what is a linkage error, and the current list does not contain UV_EACCES. If I add this patch the above code runs fine:
--- a/lib/internal/child_process.js+++ b/lib/internal/child_process.js@@ -26,7 +26,8 @@ const {
UV_ENFILE,
UV_ENOENT,
UV_ENOSYS,
- UV_ESRCH+ UV_ESRCH,+ UV_EACCES
} = process.binding('uv');
const errnoException = errors.errnoException;
@@ -308,6 +309,7 @@ ChildProcess.prototype.spawn = function(options) {
if (err === UV_EAGAIN ||
err === UV_EMFILE ||
err === UV_ENFILE ||
+ err === UV_EACCES ||
err === UV_ENOENT) {
process.nextTick(onErrorNT, this, err);
// There is no point in continuing when we've hit EMFILE or ENFILE
question is on the protocol definition of runtime error and whether UV_EACCES comes under its purview or not.
Activity
gireeshpunathil commentedon Nov 25, 2017
one can argue that
nrepresents achild processand in this case as the process was never created,nnot being fully formed makes sense.Technically it may be possible to first compose a JS object that is going to abstract the child process that is being spawned. But a more natural way of doing this is to materialize the entity first, and then abstract the entity. (the entity here being the native process).
Is it against your convictions?
ORESoftware commentedon Nov 25, 2017
eh, because the child process was never "started", I can't use an 'exit' handler on the child process, which forces me to rethink my own program design. It seems like a child was started in reality, but I don't know the internals that well. I don't see why you'd ever have to put a
try/catcharound spawn. IMO a better design would be to always usen.on('error').@bnoordhuis this seems like a design mistake in node core. Having to put try/catch around
seems wrong :) I hate try/catch lol
gireeshpunathil commentedon Mar 7, 2018
this block of code defines what is runtime error and what is a linkage error, and the current list does not contain UV_EACCES. If I add this patch the above code runs fine:
question is on the protocol definition of runtime error and whether UV_EACCES comes under its purview or not.
/cc @nodejs/child_process
child_process: define EACCES as a runtime error
child_process: define EACCES as a runtime error