mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-05 03:21:16 +08:00
R=jacktfranklin@chromium.org No-Presubmit: True Bug: none Change-Id: I52dc24b12e350787085c5e3d131cface7ea87142 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3060705 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Paul Lewis <aerotwist@chromium.org>
34 lines
617 B
JavaScript
34 lines
617 B
JavaScript
'use strict';
|
|
const errorEx = require('error-ex');
|
|
const fallback = require('json-parse-better-errors');
|
|
|
|
const JSONError = errorEx('JSONError', {
|
|
fileName: errorEx.append('in %s')
|
|
});
|
|
|
|
module.exports = (input, reviver, filename) => {
|
|
if (typeof reviver === 'string') {
|
|
filename = reviver;
|
|
reviver = null;
|
|
}
|
|
|
|
try {
|
|
try {
|
|
return JSON.parse(input, reviver);
|
|
} catch (err) {
|
|
fallback(input, reviver);
|
|
|
|
throw err;
|
|
}
|
|
} catch (err) {
|
|
err.message = err.message.replace(/\n/g, '');
|
|
|
|
const jsonErr = new JSONError(err);
|
|
if (filename) {
|
|
jsonErr.fileName = filename;
|
|
}
|
|
|
|
throw jsonErr;
|
|
}
|
|
};
|