-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
struct.pack error messages do not indicate which argument was invalid #67766
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
Comments
In this example: struct.pack('!hhhh', 0x5FFF, 0x6FFF, 0x7FFF, 0x8FFF) Python errors that the 'h' format requires -32768 <= number <= 32767, but it does not indicate which of the arguments is at fault. In this contrived example it's clearly the fourth one, but in dealing with large amounts of data it would be useful to indicate which argument was invalid. This would hopefully not be a functional change, just a slightly more helpful error message. |
Adding PyErr_SetString and PyErr_Format wrapper, with a global offset struct.pack('!h', 0x8FFFF)
Traceback (most recent call last):
File "tests.py", line 5, in <module>
struct.pack('!h', 0x8FFFF)
struct.error: Raise at offset 1, 'h' format requires -32768 <= number <= 32767 |
I think it would be better to report the number of the packed item. struct.pack() already formats similar errors when pass unsuitable number of items. >>> struct.pack('<hb', 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: pack expected 2 items for packing (got 1)
>>> struct.pack('<hb', 1, 2, 3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
struct.error: pack expected 2 items for packing (got 3)
|
That's true, but I'm not sure if there have other methods to do this. If not using global variable, we will need to change a bunch of the
Make the change to:
>>> struct.pack('hh', , 0x7FFFF, 0x8FFFF)
struct.error: 'h' format requires -32768 <= number <= 32767, got bad value at item 2 (or probably, "got bad value at index 2")
Change to snprintf.
Change to "%ld" |
@serhiy-storchaka Shall I take this over from you ? |
Go for it. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
struct.pack
out of range error messages #132857The text was updated successfully, but these errors were encountered: