Exit code for invalid jArchi is 0
5-tom opened this issue · 2 comments
Version of jArchi, Operating System
jArchi 1.6.1
OS: Linux
Expected Behaviour
Running Archi -application com.archimatetool.commandline.app -consoleLog -nosplash --script.runScript myscript.ajs
where myscript.ajs is invalid should produce a non-zero exit code
Actual Behaviour
All invalid jArchi files when ran have an exit code of 0
Steps to Reproduce the Behaviour (with attached test files/script)
- Create a .ajs file with invalid code
- Run
Archi -application com.archimatetool.commandline.app -consoleLog -nosplash --script.runScript myscript.ajs
- Run
echo $?
Normally, when running a script you can include the -abortOnException
option see here. If an exception occurs somewhere a -1 exit code will be returned.
However, jArchi handles exceptions differently so that exceptions are shown in the console and don't block the UI with an error dialog, and also because a special exception is handled to exit the script. So, in this case it's not possible to throw an exception and catch it in the CLI code and return -1 when running from the CLI.
Ok, thanks for the info!
I've just wrote a small workaround using google/zx. I'll share it here in case anyone encounters the same problem. It works by checking for the presence of a string in the stdout:
myscript.ajs
throw new Error();
console.log("here");
main.mjs
import "zx/globals";
let archi =
await $`Archi -application com.archimatetool.commandline.app -consoleLog -nosplash --script.runScript myscript.ajs`;
if (archi.exitCode === 0 && !archi.stdout.includes("here")) {
archi = new ProcessOutput(
1,
archi._signal,
archi._stdout,
archi._stderr,
archi._combined,
archi._message
);
}
console.log(archi.exitCode); // 1