Consistently wrap errors

This commit is contained in:
Henry Mercer 2023-04-06 17:04:21 +01:00
parent 555b602b2f
commit e5c2f32a9f
39 changed files with 145 additions and 122 deletions

View file

@ -113,10 +113,10 @@ export function getExtraOptionsEnvParam(): object {
}
try {
return JSON.parse(raw);
} catch (e) {
const message = e instanceof Error ? e.message : String(e);
} catch (unwrappedError) {
const error = wrapError(unwrappedError);
throw new Error(
`${varName} environment variable is set, but does not contain valid JSON: ${message}`
`${varName} environment variable is set, but does not contain valid JSON: ${error.message}`
);
}
}
@ -890,3 +890,7 @@ export function fixInvalidNotificationsInFile(
sarif = fixInvalidNotifications(sarif, logger);
fs.writeFileSync(outputPath, JSON.stringify(sarif));
}
export function wrapError(error: unknown): Error {
return error instanceof Error ? error : new Error(String(error));
}