From bb0d52719116cb06dc4f041df56bd12a9d86fc34 Mon Sep 17 00:00:00 2001 From: Matt Palmerlee Date: Fri, 10 May 2024 19:00:05 -0700 Subject: [PATCH 1/2] fix #92 this.parseError is not a function --- packages/wkt/src/wkt.js | 4 ++++ packages/wkt/test/wkt.test.js | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/wkt/src/wkt.js b/packages/wkt/src/wkt.js index 8500795..2dc67c8 100644 --- a/packages/wkt/src/wkt.js +++ b/packages/wkt/src/wkt.js @@ -7,6 +7,10 @@ 'SOURCE'; +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\''); + } +}); From 293723db747355711df4da4dc8f41ceca13641c8 Mon Sep 17 00:00:00 2001 From: john gravois Date: Wed, 15 May 2024 14:17:50 -0700 Subject: [PATCH 2/2] add code comment --- packages/wkt/src/wkt.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/wkt/src/wkt.js b/packages/wkt/src/wkt.js index 2dc67c8..b162799 100644 --- a/packages/wkt/src/wkt.js +++ b/packages/wkt/src/wkt.js @@ -7,6 +7,7 @@ 'SOURCE'; +// surface parsing errors to calling code https://github.com/zaach/jison/issues/218 parser.yy.parseError = function (err) { throw err; };