Scripts in NodeJS: when explicitly exiting the process, the exit code is ignored by Raycast
Hi Raycast team! 👋🏼
Description
I'm writing some custom scripts and needed some specific error handling. During development I realized that Raycast ignores the sub-process exit code if run "manually" on NodeJS. According to the README I was under the impression that handling could be explicitly set.
Examples
The following script ends up in Failure:
// Raycast script FAILS
throw new Error('Test');
However, the following script ends up as Success:
// Raycast script SUCCEEDS
process.exit(1);
The same happens if running asynchronous scripts
This one ends up in failure:
// Raycast script FAILS
return new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('test-error'));
}, 100);
});
but this one ends up as a success:
// Raycast script SUCCEEDS
return new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('test-error'));
}, 100);
}).catch(e => {
process.exit(1);
});
Workaround
For now I've avoided handling the errors explicitly, or I've re-thrown them to be caught by Raycast
Hey @jsmrcaga,
You are correct, Raycast currently ignores the sub-process exit code if run manually on NodeJS. For the error code of the subprocess to be recognized by Raycast you would need to rethrow it or manually return such error number. In your example:
process.exit(1);
You are exiting the subprocess but you are not actively returning the subprocess exit code from the scrip.
Hi @dehesa thanks for the answer!
Gotcha for throwing an error, works like a charm ✅
However I could not reproduce by returning the error number (return 1) itself