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

Error Code for Invalid Geojson #7331

Open
2 tasks
mstniy opened this issue Apr 9, 2021 · 5 comments
Open
2 tasks

Error Code for Invalid Geojson #7331

mstniy opened this issue Apr 9, 2021 · 5 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@mstniy
Copy link
Contributor

mstniy commented Apr 9, 2021

New Issue Checklist

Issue Description

Currently there is no error code that signifies an invalid geojson.
If the creation or the update of an object fails due to a column with a geospatial index (such as 2dsphere) containing invalid data, Parse throws a generic INTERNAL_SERVER_ERROR with no information as to exactly what went wrong.
Note that this corresponds to the Mongo error code 16755.

Steps to reproduce

  1. Create a new class, geojson_test
  2. Create a new column, called geometry, of type Object
    You can use the dashboard for both of these steps
  3. Create a geospatial index using the mongo shell:
    db.geojson_test.createIndex({"geometry": "2dsphere"})
  4. Attempt to create this object, using any sdk (JS, rest, ...):
    { "geometry": {"foo":"bar"} }

One can also create an object with an empty geometry field and later attempt to update it to { "geometry": {"foo":"bar"}} and get the same behaviour.

Actual Outcome

Parse throws a generic INTERNAL_SERVER_ERROR with no information as to exactly what went wrong:
{ "code": 1, "message": "Internal server error." }

This makes it difficult to handle invalid geojsons programmatically.
Note that the original Mongo exception gets logged by Parse, but is programmatically inaccessible.

Expected Outcome

A helpful error message, like the one returned by Mongo:
MongoError: Can't extract geo keys: ... unknown GeoJSON type: { foo: "bar" }

Failing Test Case / Pull Request

  • 🤩 I submitted a PR with a fix and a test case.
  • 🧐 I submitted a PR with a failing test case.

Environment

Server

  • Parse Server version: 4.5.0
  • Operating system: Ubuntu 18.04
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): local

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: v4.4.4
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): local

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): any
  • SDK version: n/a

Logs

See above

@mtrezza mtrezza added type:bug Impaired feature or lacking behavior that is likely assumed S4 labels Apr 9, 2021
@mtrezza
Copy link
Member

mtrezza commented Apr 9, 2021

Thanks for reporting!

I agree that the server should not crash but provide a proper error message. The steps would be:

  • See whether an existing Parse Error code (defined in Parse JS SDK) can be reused for this.
  • If not, then create a PR in Parse JS SDK for a new error (see Contribution Guide)
  • Create a PR with a failing test case that expects the error
  • Add PR changes to make the test case pass

@mtrezza
Copy link
Member

mtrezza commented Apr 9, 2021

This issue has been classified as bug with severity S4 (small/trivial):

  • Workaround: Validate GeoJSON before sending it to MongoDB

@mstniy
Copy link
Contributor Author

mstniy commented Apr 13, 2021

I have created a PR for the new error code
parse-community/Parse-SDK-JS#1342

@mtrezza
Copy link
Member

mtrezza commented Apr 14, 2021

The error code PR has been merged.

The error code won't be available until a new Parse JS SDK will be released and the dependency in Parse Server is updated. But you can already expect the Parse Error and write tests for it, they will just fail for now.

@parse-github-assistant
Copy link

parse-github-assistant bot commented Mar 7, 2022

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

2 participants