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

proposal: net: ParseIP should return an error, like other Parse functions #18757

OrangeTux opened this issue Jan 23, 2017 · 1 comment


Copy link

@OrangeTux OrangeTux commented Jan 23, 2017

net.ParseIP has 1 return value. It doesn't return a value of type error. Other parse methods like url.Parse, time.ParseDuration and net.ParseMAC return 2 values. One of a specific type, the other is of type error.

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.7.go version go1.7.4 linux/amd64

What operating system and processor architecture are you using (go env)?

GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build151269634=/tmp/go-build -gno-record-gcc-switches"

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on is best.

package main

import (

func main() {
	// Trying to parse an invalid MAC address results in an error.
	// This is expected behaviour, other Parse methods do also return
	// 2 values, like time.ParseDuration or url.Parse.
	_, err := net.ParseMAC("invalid")

	if er != nil {

	// net.ParseIP doesn't follow this signature. It just returns nil
	// when parsing failed.
	ip := net.ParseIP("invalid")

What did you expect to see?

I'd expect that net.ParseIP has this signature:

func ParseIP(s string) (IP, error)

What did you see instead?

func ParseIP(s string) IP

Copy link

@ianlancetaylor ianlancetaylor commented Jan 23, 2017

Reasonable but we can't change it now. Marking as go2.

@ianlancetaylor ianlancetaylor changed the title net.ParseIP doesn't follow signature of other Parse methods. net: ParseIP should return an error, like other Parse functions Jan 23, 2017
@ianlancetaylor ianlancetaylor added the Go2 label Jan 23, 2017
@dsnet dsnet added this to the Unplanned milestone Jan 23, 2017
@rsc rsc changed the title net: ParseIP should return an error, like other Parse functions proposal: net: ParseIP should return an error, like other Parse functions Jun 17, 2017
@gopherbot gopherbot added the Proposal label Jun 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.