Skip to content
This repository was archived by the owner on Jul 16, 2020. It is now read-only.

Commit ab8ff7e

Browse files
author
Ivan Demchenko
committed
wrap JSON.parse itself
1 parent ab2974f commit ab8ff7e

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/helper.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,19 @@ function showFancySyntaxException(rawJson, e) {
2525
].join('\n');
2626
}
2727

28+
function safeJsonParse(raw) {
29+
try {
30+
return JSON.parse(raw);
31+
}
32+
catch (e) {
33+
throw new Error(H.showFancySyntaxException(raw, e));
34+
}
35+
}
36+
2837
module.exports = {
2938
showFancySyntaxException: showFancySyntaxException,
3039
mkArray: mkArray,
3140
extractErrorPositionFromErrorMsg: extractErrorPositionFromErrorMsg,
32-
extractErrorPlace: extractErrorPlace
41+
extractErrorPlace: extractErrorPlace,
42+
safeJsonParse: safeJsonParse
3343
}

src/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,7 @@ function convertSchema(rawSchema) {
351351

352352
assert(_.isString(rawSchema));
353353

354-
try {
355-
var schema = JSON.parse(rawSchema);
356-
}
357-
catch (e) {
358-
throw new Error(H.showFancySyntaxException(rawSchema, e));
359-
}
354+
var schema = H.safeJsonParse(rawSchema);
360355

361356
delete schema.id;
362357
delete schema.$schema;

0 commit comments

Comments
 (0)