-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
bytes: have buffer.ReadFrom panic with better message with negative Read count #22097
Comments
Want to send in a change? |
I reckon that most implementations that takes in an I didn't check, but I'm pretty sure all of the |
I agree with @dsnet we shouldn't add returning of an explicit error. But the change I propose is to add to bytes.Buffer its own panic for clearly understanding what exactly happened. by analogy with https://golang.org/src/bufio/bufio.go#L80
instead of
BTW, I've checked a few io.Reader wrappers: |
Panicking with a more informative error in
Something to consider is whether the panic message should be improved with the index used. Perhaps something like:
|
@dsnet Wonderful! But I share your concerns about adding this check everywhere. Let's ask the community whether it's a problem for them actually? If so, since it's widely used error in my opinion it makes sense to put that message into a common place ( io pkg? ) as a global variable. After that we'll be able to replace all unexpexted panic cases to |
I'm not convinced about this. Negative count from For that reason, we should not be adding any global variables to package |
@dsnet thank you for the explanation Let's sum all this up:
According to the above, let's add a check to negative count from |
That is an accurate summary of what been discussed, thanks. Feel free to send a change for the check in |
Thank you, I'll take it |
Change https://golang.org/cl/67970 mentions this issue: |
Change https://golang.org/cl/68810 mentions this issue: |
What version of Go are you using (
go version
)?go version go1.9 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
I'm trying to read a bad io.Reader implementation using ioutil.ReadAll
https://play.golang.org/p/EGy1gU3s2U
What did you expect to see?
A human-readable error message, like in a case of bufio.Reader with the same io.Reader implementation
https://play.golang.org/p/AKl7_zzjhx
What did you see instead?
The text was updated successfully, but these errors were encountered: