-
Notifications
You must be signed in to change notification settings - Fork 13
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
Wrp validation update #318
Conversation
primaryHandler.go
Outdated
err = multierr.Append(err, wrp.SourceValidator(*msg)) | ||
err = multierr.Append(err, wrp.DestinationValidator(*msg)) | ||
if err != nil { | ||
logger.Warn("errors returned during WRP message validation", zap.Error(err)) |
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.
logger.Warn("errors returned during WRP message validation", zap.Error(err)) | |
logger.Warn("Found WRP message validation failures", zap.Error(err)) |
primaryHandler.go
Outdated
for _, v := range validators { | ||
err = multierr.Append(err, v.Validate(*msg)) | ||
} |
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.
i say keep the for loop pattern you had and add assert.ErrorIs
errors.Is
it'll help manage and make clear which error we'll like to return 400s for
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.
is there a different assert package? i thought assert was just for testing.
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.
nevermind i think i found the function i can use.
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.
oh sorry, I meant to say errors.Is
and not assert.ErrorIs
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.
great progress 😄 let a couple of suggestions
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #318 +/- ##
==========================================
- Coverage 20.95% 20.64% -0.32%
==========================================
Files 7 7
Lines 730 741 +11
==========================================
Hits 153 153
- Misses 575 586 +11
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
primaryHandler.go
Outdated
for _, v := range validators { | ||
err = multierr.Append(err, v.Validate(*msg)) | ||
} | ||
|
||
if err != nil { |
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.
I don't think we need this nil
check since errors.Is should handle this
if err != nil { | |
if err != nil { |
primaryHandler.go
Outdated
if err != nil { | ||
|
||
if warningErrors != nil { | ||
logger.Warn("WRP message validation failures found", zap.Error(err)) |
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.
logger.Warn("WRP message validation failures found", zap.Error(err)) | |
logger.Warn("WRP message validation warnings found", zap.Error(warningErrors)) |
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusBadRequest) | ||
fmt.Fprintf( | ||
w, | ||
`{"code": %d, "message": "%s"}`, | ||
http.StatusBadRequest, | ||
fmt.Sprintf("failed to validate WRP message: %s", err), | ||
) | ||
fmt.Sprintf("failed to validate WRP message: %s", err)) |
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.
fmt.Sprintf("failed to validate WRP message: %s", err)) | |
fmt.Sprintf("failed to validate WRP message: %s", failureError)) |
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!
What's Included:
UTF8Validator
andMessageTypeValidator
usage #315SourceValidator
andDestinationValidator
usage #314