Skip to content
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

encoding/binary: Write(net.UDPAddr.Port) silently fails #18032

Closed
jech opened this issue Nov 23, 2016 · 6 comments
Closed

encoding/binary: Write(net.UDPAddr.Port) silently fails #18032

jech opened this issue Nov 23, 2016 · 6 comments

Comments

@jech
Copy link

jech commented Nov 23, 2016

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.

https://play.golang.org/p/CtZgXsWMUL

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).

@bradfitz
Copy link
Contributor

It did return an error. You didn't check it. https://play.golang.org/p/owZlw_-2LP

@jech
Copy link
Author

jech commented Nov 23, 2016

My bad.

@jech
Copy link
Author

jech commented Nov 23, 2016 via email

@bradfitz
Copy link
Contributor

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.

@jech
Copy link
Author

jech commented Nov 23, 2016 via email

@bradfitz
Copy link
Contributor

If something returns an error, check the error. That is the rule in Go.

A panic is not appropriate in this case.

@mikioh mikioh changed the title binary.Write(net.UDPAddr.Port) silently fails encoding/binary: Write(net.UDPAddr.Port) silently fails Nov 27, 2016
@golang golang locked and limited conversation to collaborators Nov 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants