Skip to content

Commit

Permalink
catch error
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Apr 15, 2024
1 parent ef60979 commit f238460
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ export class InstallFlowCLI extends Installer {
async verifyInstall (): Promise<boolean> {
// 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

Expand Down
16 changes: 8 additions & 8 deletions extension/src/flow-cli/cli-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import { CliBinary, BinaryVersionsProvider, KNOWN_FLOW_COMMANDS } from './binary
export class CliProvider {
#selectedBinaryName: BehaviorSubject<string>
#currentBinary$: StateCache<CliBinary | null>
#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<string>(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()
})
Expand All @@ -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()
Expand All @@ -66,15 +66,15 @@ export class CliProvider {
}

async getBinaryVersions (): Promise<CliBinary[]> {
return await this.#binaryVersions.getVersions()
return await this.#binaryVersionsProvider.getVersions()
}

get binaryVersions$ (): Observable<CliBinary[]> {
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()
}
}

0 comments on commit f238460

Please sign in to comment.