1 | import { parse, ParseErrorCode } from '@sqs/jsonc-parser/lib/main';
|
2 | import { asError, createAggregateError } from './errors';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export function parseJSONCOrError(input) {
|
10 | try {
|
11 | return parseJSON(input);
|
12 | }
|
13 | catch (err) {
|
14 | return asError(err);
|
15 | }
|
16 | }
|
17 |
|
18 |
|
19 |
|
20 | function parseJSON(input) {
|
21 | const errors = [];
|
22 | const o = parse(input, errors, { allowTrailingComma: true, disallowComments: false });
|
23 | if (errors.length > 0) {
|
24 | throw createAggregateError(errors.map(v => (Object.assign({}, v, { code: ParseErrorCode[v.error], message: `Configuration parse error, code: ${v.error} (offset: ${v.offset}, length: ${v.length})` }))));
|
25 | }
|
26 | return o;
|
27 | }
|
28 |
|
\ | No newline at end of file |