[issue23578] struct.pack error messages do not indicate which argument was invalid

2022-03-23 Thread Irit Katriel


Change by Irit Katriel :


--
versions: +Python 3.11 -Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23578] struct.pack error messages do not indicate which argument was invalid

2017-02-25 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
assignee:  -> serhiy.storchaka
priority: normal -> low
stage: needs patch -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23578] struct.pack error messages do not indicate which argument was invalid

2017-02-25 Thread Louie Lu

Louie Lu added the comment:

> 1. Using global variable doesn't look good to me.

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
function arguments. Since the arguments didn't contain the
information about which item is in the process and raise the error.


> 2. "at offset 1" looks confusing to me. What is offset?

Make the change to: 
>>> struct.pack('hh', , 0x7, 0x8)
struct.error: 'h' format requires -32768 <= number <= 32767, got bad value at 
item 2

(or probably, "got bad value at index 2")

> 3. It is not safe to use the fixed length array for formatting error message. 
> Once the underlying error message can be changed and will overflow the buffer.

Change to snprintf.

> The "%zd" format in sprintf() is not portable.

Change to "%ld"

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23578] struct.pack error messages do not indicate which argument was invalid

2017-02-25 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

1. Using global variable doesn't look good to me.

2. "at offset 1" looks confusing to me. What is offset? Is this an offset of 
packed item in created bytes object? The you shouldn't get the odd number for 
the '!h' format.

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('>> struct.pack('

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23578] struct.pack error messages do not indicate which argument was invalid

2017-02-25 Thread Louie Lu

Louie Lu added the comment:

Adding PyErr_SetString and PyErr_Format wrapper, with a global offset
variable to handle this.

struct.pack('!h', 0x8)
Traceback (most recent call last):
  File "tests.py", line 5, in 
struct.pack('!h', 0x8)
struct.error: Raise at offset 1, 'h' format requires -32768 <= number <= 32767

--
nosy: +louielu

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23578] struct.pack error messages do not indicate which argument was invalid

2017-02-25 Thread Louie Lu

Changes by Louie Lu :


--
pull_requests: +262

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23578] struct.pack error messages do not indicate which argument was invalid

2016-10-08 Thread R. David Murray

Changes by R. David Murray :


--
keywords: +easy (C)
stage:  -> needs patch
versions: +Python 3.7 -Python 2.7, Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23578] struct.pack error messages do not indicate which argument was invalid

2015-03-03 Thread Alistair Lynn

New submission from Alistair Lynn:

In this example:

  struct.pack('!', 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.

--
components: Library (Lib)
messages: 237153
nosy: alynn
priority: normal
severity: normal
status: open
title: struct.pack error messages do not indicate which argument was invalid
type: enhancement
versions: Python 2.7, Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23578
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23578] struct.pack error messages do not indicate which argument was invalid

2015-03-03 Thread Ned Deily

Changes by Ned Deily n...@acm.org:


--
nosy: +mark.dickinson, meador.inge

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue23578
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com