Skip to content

Commit

Permalink
Attempt to select stack then create as fallback in ts
Browse files Browse the repository at this point in the history
  • Loading branch information
aq17 committed Nov 17, 2022
1 parent befe190 commit a86dd9b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
@@ -0,0 +1,4 @@
changes:
- type: fix
scope: sdk/nodejs
description: Attempt to select stack then create as fallback on 'createOrSelect'
14 changes: 7 additions & 7 deletions sdk/nodejs/automation/stack.ts
Expand Up @@ -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";
Expand Down Expand Up @@ -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}`);
Expand Down

0 comments on commit a86dd9b

Please sign in to comment.