mapbox/geojsonhint

Consider returning more uniform error objects

Closed this issue · 2 comments

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
}]

@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.

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