diff --git a/packages/cli/src/commands/profile/ls.ts b/packages/cli/src/commands/profile/ls.ts index ce349e29..7c878bf3 100644 --- a/packages/cli/src/commands/profile/ls.ts +++ b/packages/cli/src/commands/profile/ls.ts @@ -13,6 +13,8 @@ export default class ListProfile extends ProfileCommand { json: Flags.boolean({}), } + protected throwOnProfileNotFound = false + async run(): Promise { const { profiles, current } = await this.profileConfig.list() diff --git a/packages/cli/src/commands/profile/rm.ts b/packages/cli/src/commands/profile/rm.ts index 4bf42cfc..cd5dc01f 100644 --- a/packages/cli/src/commands/profile/rm.ts +++ b/packages/cli/src/commands/profile/rm.ts @@ -24,6 +24,8 @@ export default class RemoveProfile extends ProfileCommand static enableJsonFlag = true + protected throwOnProfileNotFound = false + async run(): Promise { const alias = this.args.name if (await this.profileConfig.delete(alias, { throwOnNotFound: !this.flags.force })) { diff --git a/packages/cli/src/profile-command.ts b/packages/cli/src/profile-command.ts index cca3bb0f..aecffec5 100644 --- a/packages/cli/src/profile-command.ts +++ b/packages/cli/src/profile-command.ts @@ -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' @@ -86,10 +86,18 @@ abstract class ProfileCommand extends BaseCommand { protected flags!: Flags protected args!: Args + protected throwOnProfileNotFound = true + public async init(): Promise { 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 } diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 430d67e4..71cac76e 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -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'