-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
codes: replace %q to %d in error string when invalid code is an integer #7188
codes: replace %q to %d in error string when invalid code is an integer #7188
Conversation
a0f7de3
to
23acaf4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
5e5c77d
to
20c42a3
Compare
21e4d71
to
0aacf4f
Compare
0aacf4f
to
a6f25ed
Compare
LGTM! |
Also, for the PR title, we usually follow the following format: So, this would be: |
Done |
Also, while you are here, could you also please change the call to |
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo the one last minor nit.
codes/codes_test.go
Outdated
|
||
var got Code | ||
if err := got.UnmarshalJSON([]byte("200")); !strings.Contains(err.Error(), wantErr) { | ||
t.Errorf("got.UnmarshalJSON(200) != %v; wantErr: %v", err, wantErr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message should have a =
instead of a !=
because we are printing got
before want
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Done
7174(Minor 'invalid code' error output suggestion) raises an issue from implementation https://github.com/grpc/grpc-go/blob/b433b9467d87d70de277ee7e1139ef2ad900bfa4/codes/codes.go that line 238
fmt.Errorf("invalid code: %q", ci)
will interpret the uint64 value as a Unicode code point and attempt to print the corresponding character. However, if invalid code is an integer and we already parsed ci as Uint, it is better to use%d
instead of%q
for the better output.Before Change,
code.UnmarshalJson("200")
returns"invalid code: 'E'"
After change,
code.UnmarshalJson("200")
returns"invalid code: 200"
RELEASE NOTES: N/A