cli: remove console.exit() #5958
Merged
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.