Skip to content

Commit 59d6669

Browse files
authored
fix: workaround for invalid lake version in v4.21.0-rc1 (#618)
This PR fixes the fallout of a small ticking time bomb that exploded in v4.21.0-rc1. Lake reports its version strings as follows, where `77cfc4d` is the commit ID of the corresponding release: ``` [mhuisi@fedora ~]$ lake --version Lake version 5.0.0-77cfc4d (Lean version 4.20.0) ``` In v4.21.0-rc1, the commit ID is `0168680`, so Lake reports the following version string: ``` [mhuisi@fedora ~]$ lake --version Lake version 5.0.0-0168680 (Lean version 4.21.0-rc1) ``` Unfortunately, `5.0.0-0168680` is *not* a [valid semantic version](https://semver.org/), since it both contains a 0 at the start and only numbers. This is fairly rare, but it now happened on v4.21.0-rc1 for the first time. The VS Code extension parses this version as part of its precondition checks, which now fails because the version is not a valid semantic version. The workaround for this issue is to remove the step that parses the version. The extension only parsed it for consistency with other precondition checks and doesn't actually do anything interesting with the version, so removing it doesn't lose us anything.
1 parent 5a938ad commit 59d6669

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

vscode-lean4/src/diagnostics/setupDiagnoser.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ export type VersionQueryResult =
2727
| { kind: 'Cancelled' }
2828
| { kind: 'InvalidVersion'; versionResult: string }
2929

30+
export type LakeAvailabilityResult =
31+
| { kind: 'Available' }
32+
| { kind: 'NotAvailable' }
33+
| { kind: 'Error'; message: string }
34+
| { kind: 'Cancelled' }
3035
export type ElanDumpStateWithoutNetQueryResult = ElanDumpStateWithoutNetResult | { kind: 'PreEagerResolutionVersion' }
3136
export type ElanDumpStateWithNetQueryResult = ElanDumpStateWithNetResult | { kind: 'PreEagerResolutionVersion' }
3237

@@ -176,14 +181,18 @@ export class SetupDiagnoser {
176181
return gitVersionResult.exitCode === ExecutionExitCode.Success
177182
}
178183

179-
async queryLakeVersion(): Promise<VersionQueryResult> {
184+
async checkLakeAvailable(): Promise<LakeAvailabilityResult> {
180185
const lakeVersionResult = await this.runLeanCommand('lake', ['--version'], 'Checking Lake version')
181-
return versionQueryResult(lakeVersionResult, /version (\d+\.\d+\.\d+(\w|-)*)/)
182-
}
183-
184-
async checkLakeAvailable(): Promise<boolean> {
185-
const lakeVersionResult = await this.queryLakeVersion()
186-
return lakeVersionResult.kind === 'Success'
186+
switch (lakeVersionResult.exitCode) {
187+
case ExecutionExitCode.Success:
188+
return { kind: 'Available' }
189+
case ExecutionExitCode.CannotLaunch:
190+
return { kind: 'NotAvailable' }
191+
case ExecutionExitCode.ExecutionError:
192+
return { kind: 'Error', message: lakeVersionResult.combined }
193+
case ExecutionExitCode.Cancelled:
194+
return { kind: 'Cancelled' }
195+
}
187196
}
188197

189198
querySystemInformation(): SystemQueryResult {

vscode-lean4/src/diagnostics/setupDiagnostics.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,33 +284,30 @@ export class SetupDiagnostics {
284284
folderUri: ExtUri,
285285
options: { toolchainOverride?: string | undefined; toolchainUpdateMode: ToolchainUpdateMode },
286286
): Promise<PreconditionCheckResult> {
287-
const lakeVersionResult = await diagnose({
287+
const lakeAvailabilityResult = await diagnose({
288288
channel,
289289
cwdUri: extUriToCwdUri(folderUri),
290290
toolchain: options.toolchainOverride,
291291
context,
292292
toolchainUpdateMode: options.toolchainUpdateMode,
293-
}).queryLakeVersion()
294-
switch (lakeVersionResult.kind) {
295-
case 'CommandNotFound':
293+
}).checkLakeAvailable()
294+
switch (lakeAvailabilityResult.kind) {
295+
case 'NotAvailable':
296296
return this.n.displaySetupErrorWithOutput(
297-
"Error while checking Lake version: 'lake' command was not found.",
297+
"Error while checking Lake availability: 'lake' command was not found.",
298298
)
299299

300-
case 'CommandError':
300+
case 'Error':
301301
return this.n.displaySetupErrorWithOutput(
302-
`Error while checking Lake version: ${lakeVersionResult.message}`,
302+
`Error while checking Lake availability: ${lakeAvailabilityResult.message}`,
303303
)
304304

305305
case 'Cancelled':
306-
return this.n.displaySetupErrorWithOutput('Error while checking Lake version: Operation cancelled.')
307-
308-
case 'InvalidVersion':
309306
return this.n.displaySetupErrorWithOutput(
310-
`Error while checking Lake version: Invalid Lake version format: '${lakeVersionResult.versionResult}'`,
307+
'Error while checking Lake availability: Operation cancelled.',
311308
)
312309

313-
case 'Success':
310+
case 'Available':
314311
return 'Fulfilled'
315312
}
316313
}

0 commit comments

Comments
 (0)