Moving this issue https://github.com/microlinkhq/tinyspawn/issues/13 to this library, since I misunderstood where the error was being thrown and how to handle it. I'll write out my confusion for future readers.
At this point, process is a Promise that can reject. Because I use TypeScript and the return type for exec is ChildProcess, I didn't realize that it was a Promise, so I didn't think it was possible for me to handle the rejection. I thought an error was being thrown in some event handler that I couldn't prevent without removing all event listeners.
But I'm able to tell TypeScript to be silent and actually handle the rejection with:
// @ts-ignore
process.catch(err => {
...
});
And no more unhandled rejection.
TL;DR: I believe the return type for the exec function is inaccurate because it's actually an extension of a Promise.
Moving this issue https://github.com/microlinkhq/tinyspawn/issues/13 to this library, since I misunderstood where the error was being thrown and how to handle it. I'll write out my confusion for future readers.
I am doing something like this:
At this point,
process
is a Promise that can reject. Because I use TypeScript and the return type forexec
isChildProcess
, I didn't realize that it was a Promise, so I didn't think it was possible for me to handle the rejection. I thought an error was being thrown in some event handler that I couldn't prevent without removing all event listeners.But I'm able to tell TypeScript to be silent and actually handle the rejection with:
And no more unhandled rejection.
TL;DR: I believe the return type for the
exec
function is inaccurate because it's actually an extension of a Promise.https://github.com/microlinkhq/youtube-dl-exec/blob/33dcbc3d5644b500ab45ccce4d7b703b55b91298/src/index.d.ts#L394-L396