mapbox / geojsonhint

IMPORTANT: This repo will be archived. Use @placemarkio/check-geojson instead
ISC License
258 stars 37 forks source link

Consider returning more uniform error objects #65

Closed knutole closed 5 years ago

knutole commented 6 years ago

Currently it's quite difficult to check for valid geojson, instead of just linting.

Different errors return completely different messages, for example:

Spelling error:

var errors = geojsonhint.hint("{
  "type": "FeatureCollection",
  "features": [
    {
      "typde": "Feature", // <- spelling 
    (...)
}");

console.log(errors) ->
[{
    line : 1,
    message : ""type" member required"
}]

Empty string:

var errors = geojsonhint.hint("");

console.log(errors) ->
[{
    error : {...},
    line : 0, 
    message : "Parse error..."
}]

Valid, but not perfect, GeoJSON:

var errors = geojsonhint.hint("{some valid geojson}");

console.log(errors) ->
[{
    level : "message",
    message : "Polygons and MultiPolygons should follow the right-hand rule"
},
{
    level : "message",
    message : "Polygons and MultiPolygons should follow the right-hand rule"
}]

Three different cases yield three completely different error objects, making it impossible to simply check for valid GeoJSON.

Would be great to get a more uniform error object, eg.:

[{
    level : "error",
    message : "Parse error",
    error : {...},
    line : NaN,
}, 
{
    level : "message",
    message : "Polygons and MultiPolygons should follow the right-hand rule",
    error : null, 
    line : 0
}]
ingalls commented 6 years ago

@knutole your proposed error format looks wonderful and I would be happy to review a PR.

If you do cut a PR please ensure I am "assigned" and cc @ingalls somewhere in the PR body.

sgillies commented 5 years ago

Closing for lack of activity. Structured errors or warnings is a good idea, but this project is not actively developed at this time.