Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS error() gives string whereas SH $? gives int #45

Open
sam-maverick opened this issue May 14, 2024 · 3 comments
Open

JS error() gives string whereas SH $? gives int #45

sam-maverick opened this issue May 14, 2024 · 3 comments

Comments

@sam-maverick
Copy link

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);
}

@nfischer
Copy link
Owner

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

@nfischer nfischer reopened this May 16, 2024
@nfischer
Copy link
Owner

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

@sam-maverick
Copy link
Author

Thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants