Skip to content

[Bug]: Download.failure() raises TypeError: expected string or bytes-like object, got 'NoneType' #2408

@heisenborg-actual

Description

@heisenborg-actual

Version

1.43.0

Steps to reproduce

from playwright.sync_api import sync_playwright

with sync_playwright() as playwright:
    browser = playwright.chromium.launch()
    page = browser.new_page()
    with page.expect_download() as download:
        try:
            page.goto('https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf')
        except:
            pass
        print(download.value.path())
        print(download.value.suggested_filename)
        print(download.value.failure())

Expected behavior

I expect the call to download.failure() to return None because the download was successful.

Actual behavior

/tmp/playwright-artifacts-4txmfy/033b3677-12a1-472e-9eeb-44041ffbd299
dummy.pdf
Traceback (most recent call last):
  File "/usr/local/app/dl-fail.py", line 13, in <module>
    print(download.value.failure())
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/playwright/sync_api/_generated.py", line 6953, in failure
    return mapping.from_maybe_impl(self._sync(self._impl_obj.failure()))
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/playwright/_impl/_sync_base.py", line 115, in _sync
    return task.result()
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/playwright/_impl/_download.py", line 55, in failure
    return await self._artifact.failure()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/playwright/_impl/_artifact.py", line 45, in failure
    return patch_error_message(await self._channel.send("failure"))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/playwright/_impl/_helper.py", line 228, in patch_error_message
    match = re.match(r"(\w+)(: expected .*)", message)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/re/__init__.py", line 167, in match
    return _compile(pattern, flags).match(string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

Additional context

No response

Environment

- Operating System: Debian 12 / Bookworm
- CPU: x86_64
- Browser: Chromium
- Python Version: 3.12.3
- Other info: Running in a docker container on MacOS 14.4.1 via Docker Desktop using python:3.12-bookworm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions