-
Notifications
You must be signed in to change notification settings - Fork 37
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
feat(webapp): add go controller for cves endpoint #1193
base: master
Are you sure you want to change the base?
Conversation
Referenced Jiras: |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1193 +/- ##
==========================================
+ Coverage 62.98% 67.70% +4.71%
==========================================
Files 70 74 +4
Lines 6800 6127 -673
==========================================
- Hits 4283 4148 -135
+ Misses 2517 1976 -541
- Partials 0 3 +3 ☔ View full report in Codecov by Sentry. |
588b16e
to
8fa2e3d
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.
looks good. Please make a MR to app-interface enabling this API so we can see PR check test results.
8fa2e3d
to
2103879
Compare
/retest |
2103879
to
77637b3
Compare
/retest |
a3bb2a3
to
537408b
Compare
/retest |
dafed49
to
1b59f95
Compare
RHINENG-13545
1b59f95
to
8744de0
Compare
func processBadRequestErrMessage(err error) error { | ||
errMessage := err.Error() | ||
if strings.HasPrefix(errMessage, "parsing time") { | ||
parts := strings.Split(errMessage, `"`) | ||
if len(parts) < 2 { | ||
return errors.New("Wrong date format (not ISO format with timezone)") | ||
} | ||
return errors.New("Wrong date format (not ISO format with timezone): " + parts[1]) | ||
} | ||
if strings.HasSuffix(errMessage, "looking for beginning of value") { | ||
parts := strings.Split(errMessage, ` `) | ||
if len(parts) < 3 { | ||
return errors.New("malformed input") | ||
} | ||
return errors.New("malformed input: invalid character " + parts[2]) | ||
} | ||
return 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.
Parsing errors based on error message and then changing the error message is not optimal. I'd prefer wrapping original error.
Error for wrong date can be for example handled when UnmarshalJSON for time fails (it would require custom type for time so UnmarshalJSON can be defined, something like https://github.com/RedHatInsights/patchman-engine/blob/master/base/types/timestamp.go). Anyways, timestamp is parsed only by bindValidateJSON
so at least move the current logic to that function.
looking for beginning of value
is returned by regex error? In that case you can wrap the error in vmaas-lib before returning regex error or return some custom error type and then change the message after checking the error type with errors.Is
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 original error parsing time "2017-01-01T00:00:00" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "Z07:00"
is clunky and requires some go-specific knowledge to understand. That's why I opted to replace it rather than to just wrap it.
invalid character 'N' looking for beginning of value
also occurs during JSON parsing, for example, when there is NaN
instead of a number.
I will move the logic. Should I also wrap the errors instead?
parts := strings.Split(errMessage, `"`) | ||
if len(parts) < 2 { | ||
return errors.New("Wrong date format (not ISO format with timezone)") | ||
} | ||
return errors.New("Wrong date format (not ISO format with timezone): " + parts[1]) |
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.
what's the purpose of splitting the error message? When it has only 1 "
then the error will be Wrong date format (not ISO format with timezone
and when there are more "
then the second part is wrapped by the new message and other parts are discarded?
If the point is to only wrap the current error, you can use errors.Wrap
from github.com/pkg/errors
which is already used in this module or https://pkg.go.dev/errors#Join
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 purpose is to get the original timestamp being parsed, the error message without one is just a fallback.
Secure Coding Practices Checklist GitHub Link
Secure Coding Checklist