Wrap JSON parsing in try/catch

This commit is contained in:
Michael B. Gale
2023-10-04 15:49:25 +01:00
parent e827ad5b71
commit bb67eddd77
3 changed files with 16 additions and 5 deletions

View File

@@ -554,9 +554,14 @@ export async function getCodeQLForCmd(
async getVersion() {
let result = util.getCachedCodeQlVersion();
if (result === undefined) {
result = JSON.parse(
await runTool(cmd, ["version", "--format=json"]),
) as VersionOutput;
const output = await runTool(cmd, ["version", "--format=json"]);
try {
result = JSON.parse(output) as VersionOutput;
} catch (err) {
throw Error(
`Invalid JSON output from \`version --format=json\`: ${output}`,
);
}
util.cacheCodeQlVersion(result);
}
return result;