Skip to content

Commit bba2f02

Browse files
committed
Force undefined version if version command fails
The assumption is that the cli is old or corrupted. In either case we want to upgrade.
1 parent 7898463 commit bba2f02

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

extensions/ql-vscode/src/cli-version.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ import { Logger } from "./logging";
66
* Get the version of a CodeQL CLI.
77
*/
88
export async function getCodeQlCliVersion(codeQlPath: string, logger: Logger): Promise<semver.SemVer | undefined> {
9-
const output: string = await runCodeQlCliCommand(
10-
codeQlPath,
11-
["version"],
12-
["--format=terse"],
13-
"Checking CodeQL version",
14-
logger
15-
);
16-
return semver.parse(output.trim()) || undefined;
9+
try {
10+
const output: string = await runCodeQlCliCommand(
11+
codeQlPath,
12+
["version"],
13+
["--format=terse"],
14+
"Checking CodeQL version",
15+
logger
16+
);
17+
return semver.parse(output.trim()) || undefined;
18+
} catch (e) {
19+
// Failed to run the version command. This might happen if the cli version is _really_ old, or it is corrupted.
20+
// Either way, we can't determine compatibility.
21+
logger.log(`Failed to run 'codeql version'. Reason: ${e.message}`);
22+
return undefined;
23+
}
1724
}

extensions/ql-vscode/src/distribution.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ export class DistributionManager implements DistributionProvider {
8080

8181
/**
8282
* Specifies whether prerelease versions of the CodeQL CLI should be accepted.
83-
*
83+
*
8484
* Suppose a user sets the includePrerelease config option, obtains a prerelease, then decides
8585
* they no longer want a prerelease, so unsets the includePrerelease config option.
8686
* Unsetting the includePrerelease config option should trigger an update check, and this
8787
* update check should present them an update that returns them back to a non-prerelease
8888
* version.
89-
*
89+
*
9090
* Therefore, we adopt the following:
91-
*
91+
*
9292
* - If the user is managing their own CLI, they can use a prerelease without specifying the
9393
* includePrerelease option.
9494
* - If the user is using an extension-managed CLI, then prereleases are only accepted when the

0 commit comments

Comments
 (0)