Skip to content

Commit 8b9dd2e

Browse files
committed
fix: Improve jsonArgs parsing error message
1 parent e5d5467 commit 8b9dd2e

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lib/preprocessor-configuration.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ function validateConfigurationEntry(
7373
args = value.args;
7474
} else {
7575
throw new Error(
76-
`Expected an array of strings (json.args), but got ${
77-
util.inspect(value)
78-
}`
79-
)
76+
`Expected an array of strings (json.args), but got ${util.inspect(
77+
value
78+
)}`
79+
);
8080
}
8181
}
8282
if (
@@ -188,7 +188,19 @@ function validateEnvironmentOverrides(
188188
if (hasOwnProperty(environment, "jsonArgs")) {
189189
let { jsonArgs } = environment;
190190
if (isString(jsonArgs)) {
191-
jsonArgs = JSON.parse(jsonArgs);
191+
try {
192+
jsonArgs = JSON.parse(jsonArgs);
193+
} catch (err) {
194+
let parseErrorMessage = "";
195+
if (err instanceof Error) {
196+
parseErrorMessage = `JSON.parse(jsonArgs) failed with message:\n${err.message}`;
197+
}
198+
throw new Error(
199+
`Expected valid JSON (jsonArgs), but got ${util.inspect(
200+
jsonArgs
201+
)}\n${parseErrorMessage}`
202+
);
203+
}
192204
}
193205
if (Array.isArray(jsonArgs) && jsonArgs.every(isString)) {
194206
overrides.jsonArgs = jsonArgs;

0 commit comments

Comments
 (0)