From f2384609de2e7bcea717648a12a1c9453bdff288 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Mon, 15 Apr 2024 16:05:27 -0700 Subject: [PATCH] catch error --- .../installers/flow-cli-installer.ts | 5 ++++- extension/src/flow-cli/cli-provider.ts | 16 ++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/extension/src/dependency-installer/installers/flow-cli-installer.ts b/extension/src/dependency-installer/installers/flow-cli-installer.ts index 50b03415..17375089 100644 --- a/extension/src/dependency-installer/installers/flow-cli-installer.ts +++ b/extension/src/dependency-installer/installers/flow-cli-installer.ts @@ -128,7 +128,10 @@ export class InstallFlowCLI extends Installer { async verifyInstall (): Promise { // Check if flow version is valid to verify install this.#context.cliProvider.refresh() - const installedVersions = await this.#context.cliProvider.getBinaryVersions() + const installedVersions = await this.#context.cliProvider.getBinaryVersions().catch((e) => { + window.showErrorMessage('Failed to check CLI version: ' + e.message) + return [] + }) const version = installedVersions.find(y => y.command === KNOWN_FLOW_COMMANDS.DEFAULT)?.version if (version == null) return false diff --git a/extension/src/flow-cli/cli-provider.ts b/extension/src/flow-cli/cli-provider.ts index 3926e5a5..963c456b 100644 --- a/extension/src/flow-cli/cli-provider.ts +++ b/extension/src/flow-cli/cli-provider.ts @@ -8,18 +8,18 @@ import { CliBinary, BinaryVersionsProvider, KNOWN_FLOW_COMMANDS } from './binary export class CliProvider { #selectedBinaryName: BehaviorSubject #currentBinary$: StateCache - #binaryVersions: BinaryVersionsProvider + #binaryVersionsProvider: BinaryVersionsProvider #settings: Settings constructor (settings: Settings) { const initialBinaryPath = settings.getSettings().flowCommand this.#settings = settings - this.#binaryVersions = new BinaryVersionsProvider([initialBinaryPath]) + this.#binaryVersionsProvider = new BinaryVersionsProvider([initialBinaryPath]) this.#selectedBinaryName = new BehaviorSubject(initialBinaryPath) this.#currentBinary$ = new StateCache(async () => { const name: string = this.#selectedBinaryName.getValue() - const versionCache = this.#binaryVersions.get(name) + const versionCache = this.#binaryVersionsProvider.get(name) if (versionCache == null) return null return await versionCache.getValue() }) @@ -43,10 +43,10 @@ export class CliProvider { // Subscribe to changes in the selected binary to update the caches this.#selectedBinaryName.pipe(distinctUntilChanged(), startWith(null), pairwise()).subscribe(([prev, curr]) => { // Remove the previous binary from the cache - if (prev != null) this.#binaryVersions.remove(prev) + if (prev != null) this.#binaryVersionsProvider.remove(prev) // Add the current binary to the cache - if (curr != null) this.#binaryVersions.add(curr) + if (curr != null) this.#binaryVersionsProvider.add(curr) // Invalidate the current binary cache this.#currentBinary$.invalidate() @@ -66,15 +66,15 @@ export class CliProvider { } async getBinaryVersions (): Promise { - return await this.#binaryVersions.getVersions() + return await this.#binaryVersionsProvider.getVersions() } get binaryVersions$ (): Observable { - return this.#binaryVersions.versions$.pipe(distinctUntilChanged(isEqual)) + return this.#binaryVersionsProvider.versions$.pipe(distinctUntilChanged(isEqual)) } // Refresh all cached binary versions refresh (): void { - this.#binaryVersions.refresh() + this.#binaryVersionsProvider.refresh() } }