Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8087292

nashorn should have a "fail-fast" option for scripting, analog to bash "set -e"

    XMLWordPrintable

Details

    • Enhancement
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • 8u45
    • 9
    • core-libs
    • b81
    • x86
    • windows_8

    Backports

      Description

        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".

        JUSTIFICATION :
        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
        rm importantFile
        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 :
        EXPECTED -
        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:
        set(ABORT_ON_CMD_FAILURE, true);

        Attachments

          Issue Links

            Activity

              People

                sundar Sundararajan Athijegannathan
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: