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/netip: normalising errors returned by ParseAddrPort #65800

Open
aimuz opened this issue Feb 20, 2024 · 1 comment
Open

proposal: net/netip: normalising errors returned by ParseAddrPort #65800

aimuz opened this issue Feb 20, 2024 · 1 comment
Labels
Milestone

Comments

@aimuz
Copy link
Contributor

aimuz commented Feb 20, 2024

Proposal Details

The current ParseAddrPort error has the following value

errors.New("not an ip:port")
errors.New("no IP")
errors.New("no port")
errors.New("missing ]")
errors.New("invalid port " + strconv.Quote(port) + " parsing " + strconv.Quote(s))
errors.New("invalid ip:port " + strconv.Quote(s) + ", square brackets can only be used with IPv6 addresses")
errors.New("invalid ip:port " + strconv.Quote(s) + ", IPv6 addresses must be surrounded by square brackets")

I would suggest turning these error values into the following

netip.ParseAddrPort(strconv.Quote(s)): not an ip:port
netip.ParseAddrPort(strconv.Quote(s)): no IP
netip.ParseAddrPort(strconv.Quote(s)): no port
netip.ParseAddrPort(strconv.Quote(s)): missing ]
netip.ParseAddrPort(strconv.Quote(s)): invalid port strconv.Quote(port)
netip.ParseAddrPort(strconv.Quote(s)): square brackets can only be used with IPv6 addresses
netip.ParseAddrPort(strconv.Quote(s)): IPv6 addresses must be surrounded by square brackets

A new error type can be created without exposing the

type parseAddrError struct {
	in  string // the string given to ParseAddrPort
	msg string // an explanation of the parse failure
}

func (err parseAddrError) Error() string {
	q := strconv.Quote
	return "netip.ParseAddrPort(" + q(err.in) + "): " + err.msg
}
@aimuz aimuz added the Proposal label Feb 20, 2024
@gopherbot gopherbot added this to the Proposal milestone Feb 20, 2024
@ianlancetaylor
Copy link
Contributor

You said what but you didn't say why.

Does the standard library have any errors that look like that? Specifically the netip.ParseAddrPort(s) part?

@seankhliao seankhliao changed the title proposal: net/netip: Normalising errors returned by ParseAddrPort proposal: net/netip: normalising errors returned by ParseAddrPort Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

3 participants