Skip to content

Conversation

@mrange
Copy link

@mrange mrange commented Oct 2, 2020

See: #152

return objectNode;
} catch (MalformedURLException | UnsupportedEncodingException e) {
throw new JsltException("Can't parse " + urlString, e);
} catch (Throwable e) {
Copy link
Author

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.

Copy link
Collaborator

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?

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.

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 :)

Copy link
Author

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"
}
Copy link
Collaborator

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.

Copy link
Author

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

Copy link
Collaborator

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests


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.

Copy link
Collaborator

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.

Copy link
Author

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

Copy link
Author

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());
Copy link
Collaborator

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?

Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use getName

@mrange
Copy link
Author

mrange commented Oct 3, 2020

I updated the code as I understood the feedback.

@biochimia
Copy link
Contributor

I would like to understand a little bit more the reasoning for using a throwOnFailures parameter, as opposed to a fallback parameter as is customary (as pointed out in #152).

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 parse-url a special enough case that it warrants its own error handling mechanism?

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 try ... catch ... expression could be introduced in the language.

@mrange
Copy link
Author

mrange commented Oct 3, 2020

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 parse-url we are interested in why it fails. With a fallback param that information is lost. parse-url as of today already returns an object so in this particular case I don't see any practical issues but I agree there's a break in the idioms used today.

I am personally not so much a favour of exceptions as no one expects the unexpected exception ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants