-
Rate limit · GitHub Access has been restricted
You have triggered a rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour. -
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
bpo-28557: error message for bad raw readinto #7496
Conversation
Would prefer to still return an OSError with the TypeError as a cause, but couldn't figure out how to do that. Hints/help would be appreciated. |
e6a4161
to
72339b2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't think you should change the exception type.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
5157566
to
e72ab00
Compare
So, I just noticed other similar places in
So that will propagate the exception for Sorry for the whiplash. |
Sorry, i'm not sure i quite follow what you mean here |
I'm saying the error handling code should look like this. |
i see your point about following conventions in the file but i think that makes this a lot less ergonomic and helpful for debugging without cause:
with cause:
|
friendly bump @benjaminp |
@csabella should we change this from awaiting changes to awaiting review again? |
Lib/test/test_io.py
Outdated
bufio = self.tp(rawio) | ||
with self.assertRaises(OSError) as cm: | ||
bufio.readline() | ||
assert cm.exception.__cause__ is None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert cm.exception.__cause__ is None | |
self.assertIsNone(cm.exception.__cause__) |
Lib/test/test_io.py
Outdated
bufio = self.tp(rawio) | ||
with self.assertRaises(OSError) as cm: | ||
bufio.readline() | ||
assert isinstance(cm.exception.__cause__, TypeError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert isinstance(cm.exception.__cause__, TypeError) | |
self.assertIsInstance(cm.exception.__cause__, TypeError) |
e72ab00
to
2b8468e
Compare
thanks for the suggestions @remilapeyre . updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @davidszotten ! Just one small nit, I'm pretty sure an error must be set when n == 1
so you don't have to check PyErr_Occurred()
too. Otherwise it looks good to me!
@@ -1483,6 +1483,15 @@ _bufferedreader_raw_read(buffered *self, char *start, Py_ssize_t len) | |||
} | |||
n = PyNumber_AsSsize_t(res, PyExc_ValueError); | |||
Py_DECREF(res); | |||
|
|||
if (n == -1 && PyErr_Occurred()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (n == -1 && PyErr_Occurred()) { | |
if (n == -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't quite understand why, but removing that check i get a segfault
here's the bottom of the stack from lldb:
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x00000001001542f5 python.exe`_PyErr_FormatVFromCause [inlined] _Py_DECREF(op=0x0000000000000000) at object.h:441:9 [opt]
frame #1: 0x00000001001542f5 python.exe`_PyErr_FormatVFromCause(tstate=0x0000000100506680, exception=0x0000000100292fc0, format="raw readinto() returned invalid value", vargs=0x00007ffeefbf9a40) at errors.c:586 [opt]
* frame #2: 0x0000000100154460 python.exe`_PyErr_FormatFromCause(exception=<unavailable>, format=<unavailable>) at errors.c:626:5 [opt]
frame #3: 0x00000001001e8508 python.exe`_bufferedreader_raw_read(self=<unavailable>, start=<unavailable>, len=8192) at bufferedio.c:1488:9 [opt]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hang on, i think i get it now. the point is that n
is the return value of the (user-defined) readinto
which means it can sometimes be -1
even without PyErr_Occurred
. this is then caught in the next if
block (and becomes "raw readinto() returned invalid length [..]")
the whole point of this pr is to help users debug bad readinto
implementations by providing more granular error messages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes sorry, this was a mistake :/
@remilapeyre no worries does that mean this is ready? pr is marked as "requested changes" from @benjaminp though he never replied to my comment about his suggested change what's the next step? |
I think your change looks good, new it needs to be reviewed by a core developer like @benjaminp and they will either merge it or ask you for changes. There is a lot of work going on on Python and they have a lot of PR to review so it may take them some time but they will get there :) |
is there a difference between the tags for "awaiting review" and "awaiting core review" that's applicable here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first is when nobody reviewed, the second is when someone who is not a core developer has made a review. It should have switched but the bot seems to have missed it.
thank you! |
Co-authored-by: Benjamin Peterson <benjamin@python.org>
https://bugs.python.org/issue28557