-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cli): error message for destroy action on non-existent stack #30374
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -578,7 +578,7 @@ export async function destroyStack(options: DestroyStackOptions) { | |
|
||
const currentStack = await CloudFormationStack.lookup(cfn, deployName); | ||
if (!currentStack.exists) { | ||
return; | ||
throw new StackNotFoundError(`Failed to destroy ${deployName}. The stack is not deployed.`); | ||
} | ||
const monitor = options.quiet ? undefined : StackActivityMonitor.withDefaultPrinter(cfn, deployName, options.stack, { | ||
ci: options.ci, | ||
|
@@ -694,3 +694,9 @@ function suffixWithErrors(msg: string, errors?: string[]) { | |
? `${msg}: ${errors.join(', ')}` | ||
: msg; | ||
} | ||
|
||
export class StackNotFoundError extends Error { | ||
constructor(message: string) { | ||
super(message); | ||
} | ||
} | ||
Comment on lines
+697
to
+702
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this error type here, please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. Any reason why you feel this is unnecessary? Saw some custom errors in the code. Thought it would be make it clear which exception is being thrown. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ import * as chokidar from 'chokidar'; | |
import * as fs from 'fs-extra'; | ||
import * as promptly from 'promptly'; | ||
import * as uuid from 'uuid'; | ||
import { DeploymentMethod } from './api'; | ||
import { DeploymentMethod, StackNotFoundError } from './api'; | ||
import { SdkProvider } from './api/aws-auth'; | ||
import { Bootstrapper, BootstrapEnvironmentOptions } from './api/bootstrap'; | ||
import { CloudAssembly, DefaultSelection, ExtendedStackSelection, StackCollection, StackSelector } from './api/cxapp/cloud-assembly'; | ||
|
@@ -620,8 +620,12 @@ export class CdkToolkit { | |
}); | ||
success(`\n ✅ %s: ${action}ed`, chalk.blue(stack.displayName)); | ||
} catch (e) { | ||
error(`\n ❌ %s: ${action} failed`, chalk.blue(stack.displayName), e); | ||
throw e; | ||
if (e instanceof StackNotFoundError) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use |
||
error(`\n ❌ %s: ${action} skipped`, chalk.blue(stack.displayName), e); | ||
} else { | ||
error(`\n ❌ %s: ${action} failed`, chalk.blue(stack.displayName), e); | ||
throw e; | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -1525,4 +1529,4 @@ function buildParameterMap(parameters: { | |
} | ||
|
||
return parameterMap; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please keep the newline at the end of the file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change, because we are changing the exit code for this command. We will not accept breaking changes to any CLI commands. Instead please add a new flag, something like
--fail-on-missing
, todestroy
, and in thisif
ensure we check bothcurrentStack.exists
andoptions.failOnMissing
, or a different name if you think a different one would be better.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be considered a breaking change even though the exception is being caught? The exit code of destroy command is not changed. The command doesn't fail if the stack doesn't exist.
The issue states
destroy
returns success even if the stack doesn't exist, if we add the flag this problem will persist with thedestroy
command.