Skip to content

Commit 9bdb680

Browse files
committed
nat: ParsePort: improve error
Unwrap the error to don't include "strconv.ParseUint" in the error message. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 9d87b06 commit 9bdb680

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

nat/nat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func ParsePort(rawPort string) (int, error) {
4949
}
5050
port, err := strconv.ParseUint(rawPort, 10, 16)
5151
if err != nil {
52-
return 0, err
52+
return 0, fmt.Errorf("invalid port '%s': %w", rawPort, errors.Unwrap(err))
5353
}
5454
return int(port), nil
5555
}

nat/nat_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestParsePort(t *testing.T) {
1616
doc: "invalid value",
1717
input: "asdf",
1818
expPort: 0,
19-
expErr: `strconv.ParseUint: parsing "asdf": invalid syntax`,
19+
expErr: `invalid port 'asdf': invalid syntax`,
2020
},
2121
{
2222
doc: "empty value",
@@ -32,7 +32,7 @@ func TestParsePort(t *testing.T) {
3232
doc: "negative value",
3333
input: "-1",
3434
expPort: 0,
35-
expErr: `strconv.ParseUint: parsing "-1": invalid syntax`,
35+
expErr: `invalid port '-1': invalid syntax`,
3636
},
3737
// FIXME currently this is a valid port. I don't think it should be.
3838
// I'm leaving this test commented out until we make a decision.
@@ -52,7 +52,7 @@ func TestParsePort(t *testing.T) {
5252
doc: "value out of range",
5353
input: "65536",
5454
expPort: 0,
55-
expErr: `strconv.ParseUint: parsing "65536": value out of range`,
55+
expErr: `invalid port '65536': value out of range`,
5656
},
5757
}
5858

0 commit comments

Comments
 (0)