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: brush up exception messages to include apiName & call log #2371

Merged
merged 2 commits into from
Mar 22, 2024

Conversation

mxschmitt
Copy link
Member

@mxschmitt mxschmitt commented Mar 22, 2024

This makes the error message more aligned to how to is in Node.js:

node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

locator.click: Timeout 2000ms exceeded.
Call log:
  - waiting for getByRole('link', { name: 'More asdfasdfinformation' })

    at /Users/maxschmitt/Developer/playwright/test.mjs:28:70 {
  name: 'TimeoutError'
}

Node.js v20.9.0
tests/async/test_locators.py::test_locator_click_timeout_error_should_contain_call_log[chromium] Traceback (most recent call last):
  File "/Users/maxschmitt/Developer/playwright-python/tests/async/test_locators.py", line 1090, in test_locator_click_timeout_error_should_contain_call_log
    await page.get_by_role("button", name="Hello Python").click(timeout=42)
  File "/Users/maxschmitt/Developer/playwright-python/playwright/async_api/_generated.py", line 14725, in click
    await self._impl_obj.click(
  File "/Users/maxschmitt/Developer/playwright-python/playwright/_impl/_locator.py", line 153, in click
    return await self._frame.click(self._selector, strict=True, **params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/maxschmitt/Developer/playwright-python/playwright/_impl/_frame.py", line 488, in click
    await self._channel.send("click", locals_to_params(locals()))
  File "/Users/maxschmitt/Developer/playwright-python/playwright/_impl/_connection.py", line 59, in send
    return await self._connection.wrap_api_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/maxschmitt/Developer/playwright-python/playwright/_impl/_connection.py", line 511, in wrap_api_call
    raise rewrite_error(exc, f"{parsed_st["apiName"]}: {exc.message}") from None
playwright._impl._errors.TimeoutError: Locator.click: Timeout 42ms exceeded.
Call log:
waiting for get_by_role("button", name="Hello Python")

Ideally we hide the internal stack traces like we do in Node.js - maybe as a follow-up?

Fixes #2369

@mxschmitt mxschmitt force-pushed the bugfix/rework-exception-messages branch 3 times, most recently from d9dc5f6 to d54ee2b Compare March 22, 2024 16:05
@mxschmitt mxschmitt force-pushed the bugfix/rework-exception-messages branch from d54ee2b to ff8e75d Compare March 22, 2024 17:04
assert error.message == "headers[0].value: expected string, got number"
assert (
error.message
== "Page.set_extra_http_headers: headers[0].value: expected string, got number"
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't lowercase page.set_extra_http_headers be more pythonic?

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure! Page = the class / interface name, matching with the docs, so probably not too bad.

@mxschmitt mxschmitt merged commit 4783148 into microsoft:main Mar 22, 2024
37 of 38 checks passed
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]: Add extra logging for the PW
2 participants