Skip to content
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

Improve error handling for geometry deserialization edge cases #13922

Merged
merged 2 commits into from
Jan 10, 2020

Conversation

jagill
Copy link
Contributor

@jagill jagill commented Jan 3, 2020

Certain geometries could be constructed (via GeometryFromText), but
could not be deserialized: it raised non-PrestoException exceptions that
bubbled up as non-catchable GenericInternalExceptions. This is a bad
user experience! This change catches those and raise catchable
PrestoExceptions.

== RELEASE NOTES ==

General Changes
* Improve error handling for geometry deserialization edge cases.

@jagill
Copy link
Contributor Author

jagill commented Jan 3, 2020

cc @mbasmanova @aweisberg

@jagill jagill changed the title Improve error handling for geometry deserialization edge cases. Improve error handling for geometry deserialization edge cases Jan 3, 2020
@jagill jagill force-pushed the corrupted-geometry branch from a4d8a11 to 58d5d39 Compare January 8, 2020 16:34
@aweisberg aweisberg self-requested a review January 8, 2020 18:05
Copy link
Contributor

@aweisberg aweisberg left a comment

Choose a reason for hiding this comment

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

Two comments about untested error paths. The one in GeometryType appears redundant with the wrapping and throwing done in the function it calls. Is there a case for having it twice?

GeometrySerializationType.getForCode throws IllegalArgumentException, is that worth catching, wrapping, and rethrowing?

@@ -83,6 +86,11 @@ public Object getObjectValue(ConnectorSession session, Block block, int position
return null;
}
Slice slice = block.getSlice(position, 0, block.getSliceLength(position));
return deserialize(slice).asText();
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this error path tested exercised by any test? Looks like deserialize catches the GeometryException and wraps it so is this necessary?

return readGeometry(input, shape, type, length);
}
catch (GeometryException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
Copy link
Contributor

Choose a reason for hiding this comment

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

When I ran TestGeometrySerialization I didn't see this exercised in the debugger.

@jagill jagill force-pushed the corrupted-geometry branch from 58d5d39 to 7ba109f Compare January 8, 2020 20:21
@aweisberg
Copy link
Contributor

I'm not advocating for removal of the error handling if you can trace the code and see where it might throw the exception. I was just asking if it was possible to put together a test case so I could see that the exception is indeed thrown by it and it's not superflous exception handling.

Do what you think is best.

@jagill jagill force-pushed the corrupted-geometry branch from 7ba109f to 58d5d39 Compare January 9, 2020 21:30
jagill added 2 commits January 9, 2020 16:30
Certain geometries could be constructed (via GeometryFromText), but
could not be deserialized: it raised non-PrestoException exceptions that
bubbled up as non-catchable GenericInternalExceptions.  This is a bad
user experience!  This change catches those and raise catchable
PrestoExceptions.
@jagill jagill force-pushed the corrupted-geometry branch from 58d5d39 to 28b3d8e Compare January 9, 2020 21:30
Copy link
Contributor

@aweisberg aweisberg left a comment

Choose a reason for hiding this comment

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

+1

@jagill
Copy link
Contributor Author

jagill commented Jan 10, 2020

Offline conversation with Ariel: Testing those exception paths is rather difficult with the current testing set up, but we know those exceptions can be thrown (and the cases that can throw them), so it's better to catch the exceptions and raise PrestoExceptions.

@mbasmanova any comments? Or does this look good to you?

Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

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

@jagill Would you share a sample error message?

@jagill
Copy link
Contributor Author

jagill commented Jan 10, 2020

@mbasmanova : Error messages for the test examples:
Invalid WKT: Invalid number of points in LineString (found 1 - must be 0 or >= 2)
Invalid WKT: Points of LinearRing do not form a closed linestring
Error constructing Polygon: shell is empty but holes are not

We can put them in the test cases explicitly, but these messages comes from the upstream libraries, which might change them between releases, leading to spurious test breakages. It won't be too hard to fix those breakages, if we think having the messages tested is important.

@mbasmanova
Copy link
Contributor

@jagill Thank you, James.

@mbasmanova mbasmanova merged commit fbb9e98 into prestodb:master Jan 10, 2020
@jagill jagill deleted the corrupted-geometry branch January 10, 2020 19:20
@aweisberg aweisberg mentioned this pull request Jan 17, 2020
7 tasks
@caithagoras caithagoras mentioned this pull request Jan 22, 2020
6 tasks
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.

3 participants