Skip to content

Conversation

@bastimeyer
Copy link
Member

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 a StreamlinkCLIError exception, which is then caught in the main() function.

There's still a lot to do here in the future. For example, the entire ConsoleOutput implementation 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 StreamlinkCLIError exception 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.

Copy link
Member

@gravyboat gravyboat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@bastimeyer bastimeyer merged commit d108858 into streamlink:master Apr 22, 2024
@bastimeyer bastimeyer deleted the cli/clierror branch April 22, 2024 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants