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

return value #599

Open
charliez0 opened this issue Dec 27, 2023 · 5 comments
Open

return value #599

charliez0 opened this issue Dec 27, 2023 · 5 comments

Comments

@charliez0
Copy link

charliez0 commented Dec 27, 2023

Describe the bug
A clear and concise description of what the bug is.
When the program triggered by asciinema exit with non-zero value, asciinema returns zero
To Reproduce

root@speedtest:~# asciinema rec -c "exit 1" test.rec
asciinema: recording asciicast to test.rec
asciinema: exit opened program when you're done
asciinema: recording finished
asciinema: asciicast saved to test.rec
root@speedtest:~# echo $?
0

Expected behavior
return non-zero when triggered program exit code non-zero
Versions:

root@speedtest:~# cat /etc/os-release
PRETTY_NAME="Ubuntu Noble Numbat (development branch)"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04 (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
root@speedtest:~# asciinema --version
asciinema 2.4.0

Additional context
Add any other context about the problem here.

@ku1ik
Copy link
Contributor

ku1ik commented Jan 8, 2024

Given asciinema itself finished without errors, finished recording successfully, I think the current behaviour is not too bad. But it really depends on what one expects here.

What do you think of an option, e.g. --return or similar, to exit with the code returned by the recorded program? script command (which asciinema was inspired by) does it via -e / --return for example.

@charliez0
Copy link
Author

Yes, it would be great to add one option so that no breaking changes would made to fix this

@moritzdietz
Copy link

I know that some cli tools have an option to "transfer" exit codes depending on what happens inside of the application.
jq for example has the option --exit-status

Sets the exit status of jq to 0 if the last output value was neither false nor null, 1 if the last output value was either false or null, or 4 if no valid result was ever produced. Normally jq exits with 2 if there was any usage problem or system error, 3 if there was a jq program compile error, or 0 if the jq program ran.

https://jqlang.github.io/jq/manual/

Another example is curl with their --fail argument:

-f, --fail
(HTTP) Fail silently (no output at all) on server errors. This is mostly done to enable scripts etc to better deal with failed attempts. In normal cases when an HTTP server fails to deliver a document, it returns an HTML document stating so (which often also describes why and more). This flag will prevent curl from outputting that and return error 22.

This method is not fail-safe and there are occasions where non-successful response codes will slip through, especially when authentication is involved (response codes 401 and 407).

Example:
curl --fail https://example.com

See also --fail-with-body.

I can see the appeal for CI stuff maybe?!

@ku1ik
Copy link
Contributor

ku1ik commented Jan 18, 2024

Many good ideas there, thanks.

I see 2 options:

a) forward exit code from the recorded shell/command as is (like script does),
b) use specific exit codes for different failure scenarios (like jq)

I'm leaning towards a) but I'm open to all ideas.

@moritzdietz
Copy link

I really like option a.) as well!

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

3 participants