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 #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion nat/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ func (p Port) Int() int {

// Range returns the start/end port numbers of a Port range as ints
func (p Port) Range() (int, int, error) {
return ParsePortRangeToInt(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()
start, end, _ := ParsePortRangeToInt(p.Port())
return start, end, nil
Comment on lines +91 to +94
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit on the fence here; the Int() function does not have an error-return in its signature, so even if the error would not be ignored, there's nowhere to send it to (other than logging or a panic);

// 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
}

The Range() function does have an error return, so the error can be handled (or ignored) by consumers.

Was there an issue you ran into, other than error-handling being inconsistent?

(for transparency; the code in this repository is quite old, and not all parts are very well designed; we're still evaluating the future of this repository, and possibly breaking it up / moving code elsewhere)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, inconsistent error handling was the only issue.

Okay, if there is a possibility that the code is being moved or broken up, this PR won't contribute much. I guess we can just close it.

}

// SplitProtoPort splits a port in the format of proto/port
Expand Down