cli: remove console.exit()#5958
Merged
Merged
Conversation
gravyboat
approved these changes
Apr 21, 2024
gravyboat
left a comment
Member
There was a problem hiding this comment.
The changes look good and are much easier to understand. If something did get missed I'm not seeing it. Everything looks like it should operate the same as before.
- Add `StreamlinkCLIError` exception class - Remove `ConsoleOutput.exit()` and remove `error` handling from `ConsoleOutput.msg_json()` - Handle raised `StreamlinkCLIError`s in `main()` - Update and refactor some CLI tests
8168307 to
a219494
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second attempt: #5044
Had these changes stashed for a while and forgot about it... This cleans up the random
console.exit()calls and instead raises aStreamlinkCLIErrorexception, which is then caught in themain()function.There's still a lot to do here in the future. For example, the entire
ConsoleOutputimplementation is pretty bad, especially in combination with the regular logging system and the download progress output, where it interweaves the progess and log lines. In the previous PR I also rewrote some tests. I didn't do this here and just did some bare minimum fixing of the existing tests, because it doesn't make sense writing/updating tests for the flawed CLI main module. Hopefully at some point in the future, the entire CLI will be rewritten with a clean design.This newly added
StreamlinkCLIErrorexception class allows adding proper exit codes. Currently everything's set to exit code 1, just like it is now (except the untouched parts where 128+2 is returned on SigInt/SigTerm). Adding specific exit codes for different kinds of errors can be figured out for the next major version release.The error behavior and error output format should be the same compared to master. Lots of tests are missing though, so there's potential for me to have changed something by accident.