Thanks to visit codestin.com
Credit goes to github.com

Skip to content

The error message for odd-length input to bytes.fromhex is cryptic #127740

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

Closed
Kodiologist opened this issue Dec 8, 2024 · 7 comments
Closed

The error message for odd-length input to bytes.fromhex is cryptic #127740

Kodiologist opened this issue Dec 8, 2024 · 7 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@Kodiologist
Copy link
Contributor

Kodiologist commented Dec 8, 2024

Bug report

Bug description:

Python 3.14.0a2+ (main, Dec  8 2024, 10:50:32) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> bytes.fromhex('deadbee')
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    bytes.fromhex('deadbee')
    ~~~~~~~~~~~~~^^^^^^^^^^^
ValueError: non-hexadecimal number found in fromhex() arg at position 7
>>> bytes.fromhex('deadbeef')
b'\xde\xad\xbe\xef'

I suggest: ValueError: fromhex() arg must be of even length.

CPython versions tested on:

3.12, CPython main branch

Operating systems tested on:

Linux

Linked PRs

@Kodiologist Kodiologist added the type-bug An unexpected behavior, bug, or error label Dec 8, 2024
@hugovk hugovk added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Dec 8, 2024
@srinivasreddy
Copy link
Contributor

@Kodiologist are you working on it ?

@Kodiologist
Copy link
Contributor Author

Nope, it's up for grabs right now.

@srinivasreddy
Copy link
Contributor

srinivasreddy commented Dec 8, 2024

Thanks 🙏. I am taking it then

@picnixz
Copy link
Member

picnixz commented Dec 8, 2024

Marking this one as a feature rather than a bug since changing exception messages may break CI (python/mypy#17849) and users may rely on exception messages.

@picnixz picnixz added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Dec 8, 2024
@rhettinger
Copy link
Contributor

users may rely on exception messages.

Users may, but users shouldn't ;-).

We don't want to change error messages unnecessarily; however, if the error message is bad, it should get fixed. To misquote Spock, the needs of many people reading error messages outweigh the needs of the few who overspecify their tests.

Bad error messages are a major source of user frustration.

@picnixz
Copy link
Member

picnixz commented Dec 8, 2024

I'm not against changing the error message but I honestly think we don't need to backport it to 3.12 and 3.13 (personally I wouldn't be against the backports but I learned the hard way that changing error messages in bug fix releases could cause un-necessary additional work =/).

srinivasreddy added a commit to srinivasreddy/cpython that referenced this issue Dec 9, 2024
…e error message to ValueError: fromhex() arg must be of even length
srinivasreddy added a commit to srinivasreddy/cpython that referenced this issue Dec 9, 2024
srinivasreddy added a commit to srinivasreddy/cpython that referenced this issue Dec 10, 2024
srinivasreddy added a commit to srinivasreddy/cpython that referenced this issue Dec 10, 2024
srinivasreddy added a commit to srinivasreddy/cpython that referenced this issue Dec 10, 2024
srinivasreddy added a commit to srinivasreddy/cpython that referenced this issue Dec 10, 2024
cfbolz pushed a commit that referenced this issue Dec 11, 2024
…r message to ValueError: fromhex() arg must be of even length (#127756)
srinivasreddy added a commit to srinivasreddy/cpython that referenced this issue Dec 11, 2024
srinivasreddy added a commit to srinivasreddy/cpython that referenced this issue Dec 11, 2024
@hauntsaninja
Copy link
Contributor

hauntsaninja commented Dec 12, 2024

Thanks for fixing this, like Raymond says, better error messages are very valuable

cfbolz chose not to backport the PR, which seems fine to me. After all, the worse error message was around for 18 years old. So closing the issue, but if someone feels strongly about backport, please mention so

srinivasreddy added a commit to srinivasreddy/cpython that referenced this issue Jan 8, 2025
…e error message to ValueError: fromhex() arg must be of even length (python#127756)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

6 participants