Wrap JSON parsing in try/catch
This commit is contained in:
parent
e827ad5b71
commit
bb67eddd77
3 changed files with 16 additions and 5 deletions
8
lib/codeql.js
generated
8
lib/codeql.js
generated
|
|
@ -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
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue