-
Notifications
You must be signed in to change notification settings - Fork 86
Do not throw 500 on invalid value type in search API #2321
Do not throw 500 on invalid value type in search API #2321
Conversation
if gormsupport.IsDataException(err) { | ||
// Remove "pq: " from the original message and return it. | ||
errMessage := strings.Replace(err.Error(), "pq: ", "", -1) | ||
return nil, 0, errors.NewBadParameterErrorFromString(errMessage) |
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.
This generates errors which look like
error listing work items for expression '
{"$AND":[
{ "number": { "$EQ" : "asd" } },
{ "space": { "$EQ" : "981fbeef-aa1f-4429-8301-70dc176079da" } }
]}': invalid input syntax for integer: "asd"
Codecov Report
@@ Coverage Diff @@
## master #2321 +/- ##
==========================================
+ Coverage 70.13% 70.15% +0.02%
==========================================
Files 171 171
Lines 16621 16629 +8
==========================================
+ Hits 11657 11666 +9
+ Misses 3832 3831 -1
Partials 1132 1132
Continue to review full report at Codecov.
|
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
gormsupport/postgres.go
Outdated
@@ -7,6 +7,7 @@ const ( | |||
errUniqueViolation = "23505" | |||
errForeignKeyViolation = "23503" | |||
errInvalidCatalogName = "3D000" | |||
errDataException = "22" // This class contains many data representation related errors. See https://www.postgresql.org/docs/9.5/static/errcodes-appendix.html |
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.
Shall we use non-version link: https://www.postgresql.org/docs/current/static/errcodes-appendix.html
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.
Yes, I have changed it a15afc9
gormsupport/postgres.go
Outdated
@@ -21,6 +22,17 @@ func IsCheckViolation(err error, constraintName string) bool { | |||
return pqError.Code == errCheckViolation && pqError.Constraint == constraintName | |||
} | |||
|
|||
// IsDataException returns true if the error is of type data exception (eg: type | |||
// mismatch, invalid delimiter, divide by zero, ...) | |||
// See https://www.postgresql.org/docs/9.5/static/errcodes-appendix.html |
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.
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.
Yes a15afc9
|
||
// Regression test for https://github.com/openshiftio/openshift.io/issues/4429 | ||
t.Run("string instead of integer", func(t *testing.T) { | ||
filter := `{"number":{"$EQ":"asd"}` |
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 curly bracket is not closed. The assertion should check for the message.
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.
Thank you. I've fixed it 5f559bc
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 depends on the input value. Do you think we should still do it?
Error for an integer would be different from the error for a string.
require.Error(t, err) | ||
assert.Equal(t, 0, count) | ||
|
||
filter = `{"number":{"$EQ":"*"}` |
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 curly bracket is not closed. The assertion should check for the message.
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.
Thank you. I've fixed it 5f559bc
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.
assert.Equal(t, 0, count) | ||
}) | ||
t.Run("UUID instead of integer", func(t *testing.T) { | ||
filter := fmt.Sprintf(`{"number":{"$EQ":"%s"}`, uuid.NewV4()) |
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 curly bracket is not closed. The assertion should check for the message.
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.
Thank you. I've fixed it 5f559bc
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.
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
# Changes **Commit:** fabric8-services/fabric8-wit@11904c7 **Author:** Konrad Kleine (193408+kwk@users.noreply.github.com) **Date:** 2018-10-10T13:49:39+02:00 Assign number to new areas/iterations and allow searching by it (fabric8-services/fabric8-wit#2311) ---- **Commit:** fabric8-services/fabric8-wit@8674b7b **Author:** Konrad Kleine (193408+kwk@users.noreply.github.com) **Date:** 2018-10-10T16:58:17+02:00 update number for existing iterations (fabric8-services/fabric8-wit#2314) ---- **Commit:** fabric8-services/fabric8-wit@e67b5e2 **Author:** nurali-techie (nurali.techie@gmail.com) **Date:** 2018-10-15T14:00:33+05:30 stop calling analytics api for cve scan reg/de-reg (fabric8-services/fabric8-wit#2316) ---- **Commit:** fabric8-services/fabric8-wit@37a913a **Author:** Baiju Muthukadan (baiju.m.mail@gmail.com) **Date:** 2018-10-15T17:07:20+05:30 Include fabric8-common as a dependency (fabric8-services/fabric8-wit#2318) ---- **Commit:** fabric8-services/fabric8-wit@e09b805 **Author:** Konrad Kleine (193408+kwk@users.noreply.github.com) **Date:** 2018-10-15T14:44:35+02:00 Use Postgres CTE to update iteration numbers (fabric8-services/fabric8-wit#2319) ---- **Commit:** fabric8-services/fabric8-wit@1724c15 **Author:** Ibrahim Jarif (jarifibrahim@gmail.com) **Date:** 2018-10-23T10:12:56+05:30 Rearrage search repository blackbox tests (fabric8-services/fabric8-wit#2322) ---- **Commit:** fabric8-services/fabric8-wit@7fda6af **Author:** Ibrahim Jarif (jarifibrahim@gmail.com) **Date:** 2018-10-23T13:49:11+05:30 Make agile default template for space creation (fabric8-services/fabric8-wit#2323) ---- **Commit:** fabric8-services/fabric8-wit@7b78cf6 **Author:** Konrad Kleine (193408+kwk@users.noreply.github.com) **Date:** 2018-10-23T11:54:01+02:00 Postpone iteration number update (fabric8-services/fabric8-wit#2325) ---- **Commit:** fabric8-services/fabric8-wit@22e3d5d **Author:** Dhriti Shikhar (dhriti.shikhar.rokz@gmail.com) **Date:** 2018-10-23T16:06:35+05:30 Enable the delete workitem endpoint (fabric8-services/fabric8-wit#2305) ---- **Commit:** fabric8-services/fabric8-wit@3d163c7 **Author:** Ibrahim Jarif (jarifibrahim@gmail.com) **Date:** 2018-10-23T17:45:11+05:30 Increase deployment timeout to 2X (fabric8-services/fabric8-wit#2327) ---- **Commit:** fabric8-services/fabric8-wit@9879836 **Author:** Ibrahim Jarif (jarifibrahim@gmail.com) **Date:** 2018-10-24T11:30:20+05:30 Do not throw 500 on invalid value type in search API (fabric8-services/fabric8-wit#2321) ---- **Commit:** fabric8-services/fabric8-wit@44739f8 **Author:** Ibrahim Jarif (jarifibrahim@gmail.com) **Date:** 2018-10-25T10:57:03+05:30 Remove redundant code and fix typo (fabric8-services/fabric8-wit#2329)
The search API uses values in the query to generate the SQL query. The backend throws internal server error if a query like
foo:123
is sent wherefoo
is of typebool
. This PR fixes this issue.With this PR
Bad Request
with error likeinstead of
Internal Server Error
Fixes openshiftio/openshift.io#4429
Depends on #2322
Todo