-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/binary: Write(net.UDPAddr.Port) silently fails #18032
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
Labels
Comments
It did return an error. You didn't check it. https://play.golang.org/p/owZlw_-2LP |
My bad. |
Thinking about it some more -- shouldn't it panic instead of returning an
error? It's clearly a programmer's error, and it's all the more confusing
since Buffer.Write is documented as never returning an error.
|
bytes.Buffer's documentation is irrelevant. You're not even making it that far. You're passing in something bogus to binary.Write and that is what is returning an error. |
bytes.Buffer's documentation is irrelevant. You're not even making it that
far. You're passing in something bogus to binary.Write and that is what is
returning an error.
I realise that. But I find this behaviour confusing, I'd expect it to
panic in this particular case.
|
If something returns an error, check the error. That is the rule in Go. A panic is not appropriate in this case. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Using go 1.7.3 on linux/amd64.
I tried to use binary.Write on a net.UDPAddr.Port, nothing was buffered. This took a while to debug.
I would have expected the binary.Write to either do the right thing (buffer two octets of data) or generate an error (either at compile time or at runtime).
The text was updated successfully, but these errors were encountered: