Skip to content

Added an error code for geospatial index failures #1342

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

Merged
merged 1 commit into from
Apr 14, 2021

Conversation

mstniy
Copy link
Contributor

@mstniy mstniy commented Apr 13, 2021

See parse-community/parse-server#7331

This PR adds a new error code for geospatial index failures. MongoDB returns the error codes 16755/16756 if one tries to create an object on a collection with a geospatial index (such as 2dsphere) but MongoDB fails to index the object, perhaps because the geojson is invalid or the index does not support the given geometry.

@codecov
Copy link

codecov bot commented Apr 13, 2021

Codecov Report

Merging #1342 (7ddf699) into master (4a75d97) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 7ddf699 differs from pull request most recent head a4da25d. Consider uploading reports for the commit a4da25d to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1342   +/-   ##
=======================================
  Coverage   99.94%   99.94%           
=======================================
  Files          60       60           
  Lines        5847     5848    +1     
  Branches     1311     1311           
=======================================
+ Hits         5844     5845    +1     
  Misses          3        3           
Impacted Files Coverage Δ
src/ParseError.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4a75d97...a4da25d. Read the comment docs.

@mtrezza
Copy link
Member

mtrezza commented Apr 13, 2021

Thanks for this PR!

Can you please just add a line above as to what the purpose of this PR is and which error scenarios this new error code should cover? This will make it easier for future investigations.

Did you take a look whether there are any existing error codes that could cover this error and if so, which ones would be the closest related?

@mstniy mstniy changed the title Added an error code for geojson index failures Added an error code for geospatial index failures Apr 13, 2021
@mstniy
Copy link
Contributor Author

mstniy commented Apr 13, 2021

Thanks for this PR!

Can you please just add a line above as to what the purpose of this PR is and which error scenarios this new error code should cover? This will make it easier for future investigations.

Did you take a look whether there are any existing error codes that could cover this error and if so, which ones would be the closest related?

I have expanded the PR description with the purpose and the scenarios the error code would cover.

Looking at ParseError.js, INCORRECT_TYPE is the closest one, but:

  • This error code is used when a field of the object to be inserted is of a type different to the one specified in the collection's schema. Although it might cover the case where the object to be inserted contains an invalid geometry, geospatial indices do not have/require a special field type, they operate on object/array/GeoPoint fields, and it is possible to have an invalid/unsupported geometry with the correct field type.
  • MongoDB does not provide separate error codes for invalid geometry vs geometry not being supported by the index

@mtrezza
Copy link
Member

mtrezza commented Apr 13, 2021

Thanks for the details. In my understanding, the errors can occur in two scenarios:

  • Trying to insert an object with invalid geometry in a collection where the geo field in indexed
  • Trying to create an index on a field where at least 1 object in the collection contains invalid geometry

I guess we can look at this on multiple levels:

  • a) It's a specific geo index - value conflict, for example INCORRECT_VALUE_FOR_GEO_INDEX
  • b) It's a general index - value conflict, for example INCORRECT_VALUE_FOR_INDEX
  • c) It's a generic INCORRECT_VALUE error analogous to the generic INCORRECT_TYPE error
  • d) It's a specific INCORRECT_GEO_VALUE error

Your suggested GEOSPATIAL_INDEX_FAILURE would be (d). Regarding the naming, I would suggest to refer to an incorrect (object) value rather than an "index failure", because that may sound like there is something wrong with the index that needs to be corrected, although you are technically right that it is the index that made this fail.

The errors (b) and (c) are more generic and therefore maybe more likely to be reusable for other scenarios. But if you think a specific error makes more sense, then we may as well go with (a) or (d). The names above are only suggestions of course.

What would you choose?

@mstniy
Copy link
Contributor Author

mstniy commented Apr 13, 2021

I agree with the scenarios you have mentioned, but I don't think the second one is relevant to Parse, because index creation is beyond its capabilities (please correct me if I am mistaken).

Peeking into the Mongo source, the error they internally use for invalid geometry, as far as I have seen, is BadValue, but this changes into a 16755 before making it to the client. INVALID_VALUE makes sense to me, and seems reusable. We can probably pass-through the error message returned by Mongo.

One disadvantage I can think of is that this would make it difficult to programmatically find out which field had an invalid value (and why), but this doesn't sound interesting either.

@mtrezza
Copy link
Member

mtrezza commented Apr 13, 2021

because index creation is beyond its capabilities (please correct me if I am mistaken).

That is indeed possible, see docs.

this would make it difficult to programmatically find out which field had an invalid value

Maybe index (and for that matter schema) setup is something one wouldn't usually do during runtime or if so, most errors would likely require manual resolving, so differentiation may not be that important.

INVALID_VALUE makes sense to me, and seems reusable. We can probably pass-through the error message returned by Mongo.

Sounds good!

@mstniy
Copy link
Contributor Author

mstniy commented Apr 14, 2021

The CI tests failed, which is interesting because this patch doesn't really change anything. I can't reproduce the error locally, though I do occasionally get different, seemingly random errors. Any ideas?

@mtrezza
Copy link
Member

mtrezza commented Apr 14, 2021

Possibly flaky tests, I restarted the tests.

I think @dplewis is more familiar with flakiness in the JS SDK, can you confirm? Maybe we should make a list of flaky tests like we have in Parse Server.

1) Parse LiveQuery can subscribe to multiple queries
835
  - AssertionError [ERR_ASSERTION]: 3 == 2

Edit: tests passed now.

Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

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

LGTM! To be sure I double checked availability of error code 162, because that is currently not easy to find out.

@mtrezza mtrezza requested review from mtrezza and dplewis and removed request for mtrezza and dplewis April 14, 2021 09:20
@mtrezza mtrezza merged commit 52cd8d4 into parse-community:master Apr 14, 2021
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.

2 participants