Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot catch ENOENT when non-node spawn is missing #185

Open
jdmairs opened this issue Mar 1, 2020 · 0 comments
Open

cannot catch ENOENT when non-node spawn is missing #185

jdmairs opened this issue Mar 1, 2020 · 0 comments

Comments

@jdmairs
Copy link

jdmairs commented Mar 1, 2020

So I'm using forever-monitor to spawn a c++ executable. It works great. I then purposefully delete the executable to test my error handling in Express.

export async function startProcess(): Promise<void> {
  return new Promise((resolve, reject) => {
    const child = forever.start(['./Foo'], {
      max: 1,
    });
    child.on('exit', () => {
      getLogger('NewJobNanny').info('Foo has exited gracefully');
      resolve();
    });

    child.on('stdout', (data: any) => {
      getLogger('NewJobNanny').info('Detecting stdout ', data);
    });

    child.on('error', (error) => {
      getLogger('NewJobNanny').error('startProcess detected error: ', error);
      reject(error);
    });
  });

I have a catch on startProcess but it does not catch. Instead my node/express app crashes with the following

events.js:200
throw er; // Unhandled 'error' event
^

Error: spawn ./Foo ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
at onErrorNT (internal/child_process.js:456:16)
at processTicksAndRejections (internal/process/task_queues.js:81:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
at onErrorNT (internal/child_process.js:456:16)
at processTicksAndRejections (internal/process/task_queues.js:81:21) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn ./Foo',
path: './Foo',
spawnargs: []
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant