-
Notifications
You must be signed in to change notification settings - Fork 120
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
jslt-152: parse-url error handling control #153
base: master
Are you sure you want to change the base?
jslt-152: parse-url error handling control #153
Conversation
@@ -1303,8 +1305,17 @@ public JsonNode call(JsonNode input, JsonNode[] arguments) { | |||
if(aURL.getUserInfo() != null && !aURL.getUserInfo().isEmpty()) | |||
objectNode.put("userinfo", aURL.getUserInfo()); | |||
return objectNode; | |||
} catch (MalformedURLException | UnsupportedEncodingException e) { | |||
throw new JsltException("Can't parse " + urlString, e); | |||
} catch (Throwable e) { |
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.
Possible regression as this catch is different. However, we ran into InvalidArgumentException
when having trailing %
which with the current code pattern gave no hints on the problem string.
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.
Throwable
is perhaps overdoing it, since it's going to catch OutOfMemoryError
and similar things. Perhaps just Exception
?
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.
Throwable
-> Exception
makes sense 👍 We just rushed the fix out without considering that.
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.
Or we can simulate NonFatal
:)
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.
Now is Exception
"error": "MalformedURLException", | ||
"message": "no protocol: this-is-an-invalid-url", | ||
"input": "this-is-an-invalid-url" | ||
} |
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.
We need a test of what happens if the second argument is not a boolean. IMHO that should be considered an error: ie, throw an exception.
We also need a test of null
handling, with and without the second parameter. (Should have had a null
test already, sorry.) I think null
input should lead to null
output, regardless of the value of the second parameter.
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 am unsure how you typically tests for failures. Do you have an example? I looked in the query-tests.yaml and found no obvious cases to me
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.
See function-error-tests.json
for examples.
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.
Added tests
|
||
Parses `url` and returns an object with keys [`scheme`, `userinfo`, `host`, `port` `path`, `query`, `parameters`, `fragment` ] | ||
|
||
If the optional `throwOnFailure` argument is not specified invalid URLs will generate an exception. If `throwOnFailure` is set to `false` the `parse-url` returns | ||
an object indicating an error occurred. | ||
|
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.
We need to document the shape of that object, and have an example.
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 added some examples below but I agree we could add more documentation on the shape both when good and bad input
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.
Updated with more detaild examples.
} else { | ||
final ObjectNode errorNode = NodeUtils.mapper.createObjectNode(); | ||
Class errorClass = e.getClass(); | ||
errorNode.put("error", errorClass.getSimpleName()); |
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.
Why not the full class name?
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 feel strongly over this. I can change to full class name.
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.
Changed to use getName
I updated the code as I understood the feedback. |
I would like to understand a little bit more the reasoning for using a My concern is that the proposed approach is not general and won't cleanly apply to cases where the return value is not an object. Is I suppose we're bound to find other cases where exception handling is warranted, and having a common way to handle errors would be preferable. Say a |
This "fix" was rushed as we had a pressing concern to address in our pipeline so I don't claim it's perfect as is. When it comes to I am personally not so much a favour of exceptions as no one expects the unexpected exception ;) |
See: #152