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
No known key found for this signature in database
GPG key ID: FF5E2765BD00628F
3 changed files with 16 additions and 5 deletions

8
lib/codeql.js generated
View file

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

File diff suppressed because one or more lines are too long

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;