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

Inconsistent Error Handling in nat Package #112

Open
ashwek opened this issue Jan 16, 2024 · 0 comments · May be fixed by #113
Open

Inconsistent Error Handling in nat Package #112

ashwek opened this issue Jan 16, 2024 · 0 comments · May be fixed by #113

Comments

@ashwek
Copy link

ashwek commented Jan 16, 2024

A minor inconsistency in error handling between two functions in the Port type.

In the Int function, there is a comment suggesting that the error should be ignored:

// Int returns the port number of a Port as an int
func (p Port) Int() int {
portStr := p.Port()
// We don't need to check for an error because we're going to
// assume that any error would have been found, and reported, in NewPort()
port, _ := ParsePort(portStr)
return port
}

However, in the Range function, there is no similar comment, and the error is returned, even though the same case applies here:

// Range returns the start/end port numbers of a Port range as ints
func (p Port) Range() (int, int, error) {
return ParsePortRangeToInt(p.Port())
}

Suggestion

For consistency and to adhere to the principle of least surprise, it would be beneficial to add a similar comment in the Range function and ignore the error.

@ashwek ashwek linked a pull request Jan 16, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant