Skip to content

webbrowser: fix propagation of BaseException #5930

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

Conversation

bastimeyer
Copy link
Member

  • Fix KeyboardInterrupt/SystemExit exceptions not being propagated in nested ExceptionGroups
  • Fix compatibility with exceptiongroup<=1.1.1 by avoiding their catch() context manager
  • Add missing test for (re-)raising different exception types

Fixes #5929

  1. exceptiongroup>=1.1.2 fixed their incorrect behavior of raising an ExceptionGroup when raising non-group-exceptions in the callback function passed to their catch() context manager:
    https://github.com/agronholm/exceptiongroup/blob/1.1.2/CHANGES.rst
    Due to this change, we can't use the catch() context manager anymore and we need to catch all BaseExceptionGroups instead and get a sub-group of the exceptions we're looking for.
  2. Instead of re-raising the first exception of the matching group, we're now traversing the group stack, so that nested exception groups don't get re-raised and only the first matching exception object itself.

@bastimeyer

This comment was marked as outdated.

Copy link
Contributor

@amurzeau amurzeau left a comment

Choose a reason for hiding this comment

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

I've tested this commit on Debian Stable and tests are passing 👍

client_integrity = CDPClient.launch(
session,
acquire_client_integrity_token,
# headless mode gets detected by Twitch, so we have to disable it regardless the user config
headless=False,
)
except BaseExceptionGroup:
Copy link
Contributor

Choose a reason for hiding this comment

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

On recent python version, if there is a single exception, will this still catch it if the BaseExceptionGroup is unwraped ?
I'm not sure if this can really happen though as tests are passing.

Copy link
Member Author

Choose a reason for hiding this comment

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

trio.run() is called with strict_exception_groups=True, so only exception groups can be raised from trio.Nursery contexts. That was the whole reason why trio's 0.25 was a breaking change for us and why we now have to set this argument explicitly on older versions of trio.

There are a couple of cases though where we actually want to catch and log non-group exceptions and then continue running the plugin code without retrieving the client-integrity token, namely resolve_executable(), find_free_port_ipv4(), tempfile.TemporaryDirectory(), etc. Let me fix this real quick...

Copy link
Contributor

@amurzeau amurzeau Apr 9, 2024

Choose a reason for hiding this comment

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

Indeed I forgot that strict_exception_groups=True option, thanks for the explanation.
Still good on Debian Stable with 0cc9f86.

- Fix `KeyboardInterrupt`/`SystemExit` exceptions
  not being propagated in nested `ExceptionGroup`s
- Fix compatibility with `exceptiongroup<=1.1.1`
  by avoiding their `catch()` context manager
- Add missing test for (re-)raising different exception types
@bastimeyer bastimeyer force-pushed the webbrowser/fix-exceptiongroup-lte-1.1.1 branch from e5d03cb to 0cc9f86 Compare April 9, 2024 22:12
@bastimeyer bastimeyer merged commit d5aa26f into streamlink:master Apr 9, 2024
@bastimeyer bastimeyer deleted the webbrowser/fix-exceptiongroup-lte-1.1.1 branch April 9, 2024 23:25
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.

tests: failure caused exceptions groups in test_webbrowser
2 participants