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

fix: report route handler errors to the user after they completed #2321

Merged
merged 4 commits into from
Feb 26, 2024

Conversation

mxschmitt
Copy link
Member

Issue: Exceptions which will get thrown in route handlers after route.{fulfill,continue,abort} got called,
won't get surfaced to the user in the sync and async version of Playwright for Python.

Scope: Event handlers which use asyncio.create_task

  • {BrowserContext,Page}.on("route")
  • {Page}.on({"route", "locatorHandlerTriggered"})

There were multiple issues in the implementation:

  1. playwright/_impl/_helper.py (sync only): we were only waiting until a handler's {continue,fulfill,abort} got called, and did not wait until the actual callback completed. Fix: Wait until the handler completed.
  2. playwright/_impl/_connection.py:423 (sync only): We call event listeners manually, this means that pyee's "error" event is not working there. Fix: attach a done callback manually, like pyee is doing inside their library.
  3. playwright/_impl/_connection.py:56 (async): attach an "error" event handler for the async error reporting
  4. playwright/_impl/_connection.py:90 if we report an error to the user, we should cancel the underlying future otherwise a warning gets emitted, that there was a future exception never received.

This should resolve #2136.

Issue: Exceptions which will get thrown in route handlers after route.{fulfill,continue,abort} got called,
won't get surfaced to the user in the sync and async version of Playwright for Python.

Scope: Event handlers which use asyncio.create_task
  - {BrowserContext,Page}.on("route")
  - {Page}.on({"route", "locatorHandlerTriggered"})

There were multiple issues in the implementation:

1. `playwright/_impl/_helper.py` (sync only): we were only waiting until a handler's {continue,fulfill,abort} got called, and did not wait until the actual callback completed. Fix: Wait until the handler completed.
2. `playwright/_impl/_connection.py:423` (sync only): We call event listeners manually, this means that `pyee`'s `"error"` event is not working there. Fix: attach a done callback manually, like pyee is doing inside their library.
3. `playwright/_impl/_connection.py:56` (async): attach an `"error"` event handler for the async error reporting
4. `playwright/_impl/_connection.py:90` if we report an error to the user, we should cancel the underlying future otherwise a warning gets emitted, that there was a future exception never received.
@mxschmitt mxschmitt force-pushed the fix-route-error-reporting branch from 1256fba to 516e753 Compare February 26, 2024 13:11
@mxschmitt mxschmitt marked this pull request as ready for review February 26, 2024 14:15
if exc:
self._on_event_listener_error(exc)

def _listener_with_error_handler_attached(params: Any) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make sure we have test coverage for this.

@mxschmitt mxschmitt merged commit 37bce20 into main Feb 26, 2024
38 checks passed
@mxschmitt mxschmitt deleted the fix-route-error-reporting branch February 26, 2024 18:24
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

Successfully merging this pull request may close these issues.

[Feature] Document page.route
2 participants