shelljs-transpiler icon indicating copy to clipboard operation
shelljs-transpiler copied to clipboard

JS `error()` gives string whereas SH `$?` gives int

Open sam-maverick opened this issue 1 year ago • 3 comments

Input (bash) code

some command
RESULT=$?
if [ $RESULT != 0 ]; then
    echo "Aborting on $RESULT, command failed:"
    exit $RESULT
fi

Expected output ShellJS (JavaScript) code

exec('some command');
env.RESULT = (error()=='null' ? 0 : 1);
if (env.RESULT !== 0) {
  echo('Aborting on ' + env.RESULT + ', command failed:');
  exit(env.RESULT);
}

Actual output ShellJS (JavaScript) code

exec('some command');
env.RESULT = error();
if (env.RESULT !== 0) {
  echo('Aborting on ' + env.RESULT + ', command failed:');
  exit(env.RESULT);
}

sam-maverick avatar May 14 '24 09:05 sam-maverick

This will be supported in shell.errorCode(). That will be in the next shelljs release when I get around to it.

nfischer avatar May 16 '24 04:05 nfischer

I'll keep this open in case someone wants to update the transpiler to use the new API when it's available.

nfischer avatar May 16 '24 04:05 nfischer

Thanks for the feedback!

sam-maverick avatar May 16 '24 17:05 sam-maverick