From bd125a089b1c52799817e4f591cb9b089e1b17e8 Mon Sep 17 00:00:00 2001 From: Graham McGregor Date: Wed, 17 Feb 2021 16:41:02 -0500 Subject: [PATCH] Handle invalid JSON --- src/json-helper.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/json-helper.js b/src/json-helper.js index 3ba1fef..1845afe 100644 --- a/src/json-helper.js +++ b/src/json-helper.js @@ -17,7 +17,13 @@ const jsonSourceMap = require("json-source-map"); * @returns {string|null} */ function getJsonPathFromRawLocation(rawJson, location) { - let { pointers } = jsonSourceMap.parse(rawJson); + let parsed = { pointers: {} }; + try { + parsed = jsonSourceMap.parse(rawJson); + } catch (err) { + return null; + } + let { pointers } = parsed; let pathEntry = Object.entries(pointers).find( /** @param {[string, Pointer]} e */ ([path, pointer]) => {