Skip to content

Commit

Permalink
avoid error on some commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon committed Feb 6, 2024
1 parent 819dd01 commit f65e2d0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/cli/src/commands/profile/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export default class ListProfile extends ProfileCommand<typeof ListProfile> {
json: Flags.boolean({}),
}

protected throwOnProfileNotFound = false

async run(): Promise<unknown> {
const { profiles, current } = await this.profileConfig.list()

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/profile/rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default class RemoveProfile extends ProfileCommand<typeof RemoveProfile>

static enableJsonFlag = true

protected throwOnProfileNotFound = false

async run(): Promise<unknown> {
const alias = this.args.name
if (await this.profileConfig.delete(alias, { throwOnNotFound: !this.flags.force })) {
Expand Down
12 changes: 10 additions & 2 deletions packages/cli/src/profile-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path'
import { Command, Flags, Interfaces } from '@oclif/core'
import {
tryParseUrl, LocalProfilesConfig, Profile, Store, detectCiProvider, fsTypeFromUrl,
localProfilesConfig, telemetryEmitter, LocalProfilesConfigGetResult,
localProfilesConfig, telemetryEmitter, LocalProfilesConfigGetResult, ProfileLoadError,
} from '@preevy/core'
import { BaseCommand, text } from '@preevy/cli-common'
import { fsFromUrl } from './fs.js'
Expand Down Expand Up @@ -86,10 +86,18 @@ abstract class ProfileCommand<T extends typeof Command> extends BaseCommand<T> {
protected flags!: Flags<T>
protected args!: Args<T>

protected throwOnProfileNotFound = true

public async init(): Promise<void> {
await super.init()
const { profileConfig, flags } = this
const profile = await findProfile({ profileConfig, flags })
const profile = await findProfile({ profileConfig, flags }).catch(e => {
if (!(e instanceof ProfileLoadError) || this.throwOnProfileNotFound) {
throw e
}
this.logger.warn(`Profile load error: ${e.message}`)
return undefined
})
if (!profile) {
return
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export {
profileStore, Profile, ProfileStore, ProfileStoreRef, ProfileStoreTransaction, ProfileEditor,
ProfileEditorOp,
link, Org, LocalProfilesConfigGetResult,
ProfileLoadError,
} from './profile/index.js'
export { telemetryEmitter, registerEmitter, wireProcessExit, createTelemetryEmitter, machineId } from './telemetry/index.js'
export { fsTypeFromUrl, Store, VirtualFS, FsReader, localFsFromUrl, localFs } from './store/index.js'
Expand Down

0 comments on commit f65e2d0

Please sign in to comment.