diff --git a/packages/wkt/src/wkt.js b/packages/wkt/src/wkt.js index 8500795..b162799 100644 --- a/packages/wkt/src/wkt.js +++ b/packages/wkt/src/wkt.js @@ -7,6 +7,11 @@ 'SOURCE'; +// surface parsing errors to calling code https://github.com/zaach/jison/issues/218 +parser.yy.parseError = function (err) { + throw err; +}; + function PointArray (point) { this.data = [point]; this.type = 'PointArray'; diff --git a/packages/wkt/test/wkt.test.js b/packages/wkt/test/wkt.test.js index e0cd779..c82860d 100644 --- a/packages/wkt/test/wkt.test.js +++ b/packages/wkt/test/wkt.test.js @@ -1035,3 +1035,16 @@ test('should parse a GEOMETRYCOLLECTION with ZM property', function (t) { } }); }); + +test('should fail with friendly error message when wkt is invalid', function (t) { + t.plan(1); + + const input = 'POINT(30,10)'; + + try { + wktToGeoJSON(input); + } catch (err) { + const error = err.toString(); + t.deepEqual(error, 'Error: Unable to parse: Parse error on line 1:\nPOINT(30,10)\n--------^\nExpecting \'DOUBLE_TOK\', got \'COMMA\''); + } +});