[Python-checkins] cpython: Touch up exception messaging
Ezio Melotti
ezio.melotti at gmail.com
Sat Jan 26 18:25:18 CET 2013
Hi,
I'm not sure these changes are an improvement.
On Fri, Jan 25, 2013 at 8:49 PM, brett.cannon
<python-checkins at python.org> wrote:
> http://hg.python.org/cpython/rev/792810303239
> changeset: 81735:792810303239
> user: Brett Cannon <brett at python.org>
> date: Fri Jan 25 13:49:19 2013 -0500
> summary:
> Touch up exception messaging
> [...]
> magic = data[:4]
> raw_timestamp = data[4:8]
> raw_size = data[8:12]
> if magic != _MAGIC_BYTES:
> - msg = 'bad magic number in {!r}: {!r}'.format(name, magic)
> + msg = 'incomplete magic number in {!r}: {!r}'.format(name, magic)
Here 2 things could go wrong:
1) magic is less than 4 bytes (so it could be "incomplete");
2) magic is 4 bytes, but it's different (so it's "invalid" or "bad");
For this to be "incomplete" the size of the whole file should be less
than 4 bytes, and it's unlikely that in a 3bytes-long file the content
is an incomplete magic number. It's much more likely than it's not a
magic number at all, or that it is a bad/wrong/invalid 4-bytes magic
number, so the previous error looked better to me.
> raise ImportError(msg, **exc_details)
> elif len(raw_timestamp) != 4:
> - message = 'bad timestamp in {!r}'.format(name)
> + message = 'incomplete timestamp in {!r}'.format(name)
> _verbose_message(message)
> raise EOFError(message)
> elif len(raw_size) != 4:
> - message = 'bad size in {!r}'.format(name)
> + message = 'incomplete size in {!r}'.format(name)
If we arrived here the magic number was right, so this are probably
the timestamp and size, but for this to fail the whole file should be
less than 8 or 12 bytes (unless I misread the code).
Something like "reached EOF while reading timestamp/size" would
probably be more informative.
Best Regards,
Ezio Melotti
More information about the Python-checkins
mailing list