Skip to content

encodings.idna: Unexpanded f-string in "Unsupported error handling" exception #135069

Closed
@danielhollas

Description

@danielhollas
Contributor

Bug report

Bug description:

The exception string in encondings.idna.IncrementalDecoder is missing the 'f' prefix.

raise UnicodeError("Unsupported error handling: {errors}")

The exception can be triggered with this snippet.

from encodings.idna import IncrementalDecoder    
decoder = IncrementalDecoder(errors='boom!')    
decoder.decode(b'')

On main

$ ./python test.py
Traceback (most recent call last):
  File "/home/hollas/software/cpython/test.py", line 3, in <module>
    decoder.decode(b'')
    ~~~~~~~~~~~~~~^^^^^
  File "<frozen codecs>", line 325, in decode
  File "/home/hollas/software/cpython/Lib/encodings/idna.py", line 319, in _buffer_decode
    raise UnicodeError("Unsupported error handling: {errors}")
UnicodeError: Unsupported error handling: {errors}

The issue also exists on Python 3.13 and 3.14, but not on 3.12

$ uvx python@3.12 test.py
Traceback (most recent call last):
  File "/home/hollas/software/cpython/test.py", line 3, in <module>
    decoder.decode(b'')
  File "<frozen codecs>", line 322, in decode
  File "/usr/lib64/python3.12/encodings/idna.py", line 264, in _buffer_decode
    raise UnicodeError("Unsupported error handling "+errors)
UnicodeError: Unsupported error handling boom!

(I'll submit a PR shortly)

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Activity

danielhollas

danielhollas commented on Jun 3, 2025

@danielhollas
ContributorAuthor

Note: I was inspired by the same issue reported in #134970 and used ruff linter to find this bug, specifically its RUF024 (missing-f-string-syntax) rule.

ruff check --target-version=py314 --preview --select RUF027 Lib/

It found two other hits in Lib/test/support/__init__.py, I'll file a separate issue for those.

added a commit that references this issue on Jul 3, 2025

gh-135069: Fix exception message in encodings.idna module (#135071)

8dc3383
added 2 commits that reference this issue on Jul 3, 2025

pythongh-135069: Fix exception message in encodings.idna module (pyth…

pythongh-135069: Fix exception message in encodings.idna module (pyth…

added 2 commits that reference this issue on Jul 3, 2025

[3.14] gh-135069: Fix exception message in encodings.idna module (GH-…

4bc9c01

[3.13] gh-135069: Fix exception message in encodings.idna module (GH-…

fc77192
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @danielhollas@picnixz

      Issue actions

        encodings.idna: Unexpanded f-string in "Unsupported error handling" exception · Issue #135069 · python/cpython