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
test: Log input to json.Unmarshal
when it fails
#16099
Conversation
2632ef5
to
742f3dd
Compare
test/helpers/cmd.go
Outdated
@@ -85,7 +85,7 @@ func (b *CmdStreamBuffer) Filter(filter string) (*FilterBuffer, error) { | |||
|
|||
err := json.Unmarshal(b.Bytes(), &data) | |||
if err != nil { | |||
return nil, fmt.Errorf("could not parse JSON from command %q", b.Cmd()) | |||
return nil, fmt.Errorf("could not parse JSON from command %q\n%s\n%s", b.Cmd(), err, b.Bytes()) |
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.
Sorry one more nit, %w
for errors
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.
That doesn't seem consistent across the codebase. We're using %s
, %v
, and %w
according to git grep -P "fmt.Errorf.*, err"
. https://github.com/golang/go/wiki/CodeReviewComments also points to %v
.
I'm happy to change but not sure to understand the logic. I also don't think it will scale if we rely solely on reviews to catch this.
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.
@pchaigno It's relatively new and it seems like the code review doc hasn't been updated for it :/
Unfortunately, yes there's inconsistency in the codebase as it sometimes slips by. In this case, consistency is not better--we should just use the correct format specifier when we can :)
Doubly unfortunate in terms of enforcement, we have gone back and forth on this. We used to have some linter that would look at these things, but we removed it because it was too noisy with unhelpful suggestions. @sayboras Do you know if our GH Actions Go linter can pick this up?
json.Unmarshal sometimes fails to parse its input. We should log the input in such cases to figure out what happened. This is currently causing a test to (rarely) flake. Signed-off-by: Paul Chaignon <paul@cilium.io>
742f3dd
to
b929023
Compare
test-me-please |
k8s-1.20-kernel-4.19 failed due to #16154. Other failing tests are not required and not affected by these changes anyway. Reviews are in. Marking as ready to merge. |
json.Unmarshal
sometimes fails to parse its input. We should log the input in such cases to figure out what happened. This is currently causing a test to (rarely) flake (cf. #16088).