From a86dd9b52b6e1ebde461e69f833fc4f2706d0a16 Mon Sep 17 00:00:00 2001 From: aq17 Date: Thu, 17 Nov 2022 15:28:26 -0800 Subject: [PATCH] Attempt to select stack then create as fallback in ts --- ...-then-create-as-fallback-on-createorselect.yaml | 4 ++++ sdk/nodejs/automation/stack.ts | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 changelog/pending/20221117--sdk-nodejs--attempt-to-select-stack-then-create-as-fallback-on-createorselect.yaml diff --git a/changelog/pending/20221117--sdk-nodejs--attempt-to-select-stack-then-create-as-fallback-on-createorselect.yaml b/changelog/pending/20221117--sdk-nodejs--attempt-to-select-stack-then-create-as-fallback-on-createorselect.yaml new file mode 100644 index 000000000000..64282b7a4baf --- /dev/null +++ b/changelog/pending/20221117--sdk-nodejs--attempt-to-select-stack-then-create-as-fallback-on-createorselect.yaml @@ -0,0 +1,4 @@ +changes: +- type: fix + scope: sdk/nodejs + description: Attempt to select stack then create as fallback on 'createOrSelect' diff --git a/sdk/nodejs/automation/stack.ts b/sdk/nodejs/automation/stack.ts index 9dbd021d6f01..de91d8cc6bdc 100644 --- a/sdk/nodejs/automation/stack.ts +++ b/sdk/nodejs/automation/stack.ts @@ -24,7 +24,7 @@ import TailFile from "@logdna/tail-file"; import * as log from "../log"; import { CommandResult, runPulumiCmd } from "./cmd"; import { ConfigMap, ConfigValue } from "./config"; -import { StackAlreadyExistsError } from "./errors"; +import { StackNotFoundError } from "./errors"; import { EngineEvent, SummaryEvent } from "./events"; import { LanguageServer, maxRPCMessageSize } from "./server"; import { Deployment, PulumiFn, Workspace } from "./workspace"; @@ -105,12 +105,12 @@ export class Stack { this.ready = workspace.selectStack(name); return this; case "createOrSelect": - this.ready = workspace.createStack(name).catch((err) => { - if (err instanceof StackAlreadyExistsError) { - return workspace.selectStack(name); - } - throw err; - }); + this.ready = workspace.selectStack(name).catch((err) => { + if (err instanceof StackNotFoundError) { + return workspace.createStack(name); + } + throw err; + }) return this; default: throw new Error(`unexpected Stack creation mode: ${mode}`);