A DESCRIPTION OF THE REQUEST :
When I write a script, I want it to fail as soon as one of the commands doesn't return normally (i.e. has non-zero exit code). This functionality is available in other shells, e.g. in bash it's "set -e".
This makes scripts safer, by aborting them as soon as a command fails & preventing other commands from causing more harm. A simple example:
cp importantFile anotherFile
Assuming the first command fails & there's no fail-fast, "importantFile" will be lost.
It also greatly helps in debugging: with this fail-fast behavior, Nashorn could tell exactly which command failed. Without it, a script may run fine for some time after the failed command, and then suddenly crash on a seemingly unrelated command. It may be very hard at that point to find out what went wrong.
Currently, the alternatives are:
- to explicitly check $EXIT after each command. This results in a lot of boilerplate code.
- to create a helper function to wrap all commands. This implies that you have to run all commands by invoking a function, instead of being able to use the much cleaner backticks syntax.
EXPECTED VERSUS ACTUAL BEHAVIOR :
I would like a way to specify fail-fast behavior for Nashorn scripts. It should be possible to specify this in the script itself, so I can just run:
jjs -scripting myNashornScript.js
For example, by introducing a new scripting mode function to set certain options: