Skip to content

Commit 23acaf4

Browse files
committed
Replace %q to %d for invalid code string formatting
1 parent 5a24fc1 commit 23acaf4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

codes/codes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func (c *Code) UnmarshalJSON(b []byte) error {
235235

236236
if ci, err := strconv.ParseUint(string(b), 10, 32); err == nil {
237237
if ci >= _maxCode {
238-
return fmt.Errorf("invalid code: %q", ci)
238+
return fmt.Errorf("invalid code: %d", ci)
239239
}
240240

241241
*c = Code(ci)

codes/codes_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,11 @@ func (s) TestUnmarshalJSON_MarshalUnmarshal(t *testing.T) {
9191
}
9292
}
9393
}
94+
95+
func (s) TestUnmarshalJSON_InvalidIntegerCode(t *testing.T) {
96+
var got Code
97+
err := got.UnmarshalJSON([]byte("200"))
98+
if err.Error() != "invalid code: 200" { // for integer invalid code, expect integer value in error message
99+
t.Errorf("got.UnmarshalJSON(200) != invalid code: 200; got=%v", err.Error())
100+
}
101+
}

0 commit comments

Comments
 (0)