-
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
Conversation
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.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
Clarification Request - regarding integration tests. Also, change in CLI code. |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week. |
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.
You will need a CLI integration test for this feature. The CLI integration tests all live here: https://github.com/aws/aws-cdk/tree/main/packages/%40aws-cdk-testing/cli-integ. The readme provides guidance in authoring and running them locally.
return; | ||
throw new StackNotFoundError(`Failed to destroy ${deployName}. The stack is not deployed.`); |
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
, to destroy
, and in this if
ensure we check both currentStack.exists
and options.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 the destroy
command.
|
||
export class StackNotFoundError extends Error { | ||
constructor(message: string) { | ||
super(message); | ||
} | ||
} |
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.
We don't need this error type here, please use throw new Error('message');
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.
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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use instanceof
, instead check with e.message.includes()
.
@@ -1525,4 +1529,4 @@ function buildParameterMap(parameters: { | |||
} | |||
|
|||
return parameterMap; | |||
} | |||
} |
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.
Please keep the newline at the end of the file.
➡️ PR build request submitted to A maintainer must now check the pipeline and add the |
This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week. |
This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error. |
Comments on closed issues and PRs are hard for our team to see. |
The pull request linter fails with the following errors:
PRs must pass status checks before we can provide a meaningful review. If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing |
Closes #22240
Reason for this change
Description of changes
While running destroy command if a stack is not deployed then an error message will be displayed but the operation won't be interrupted.
Description of how you validated changes
I need some help with testing. I couldn't find a way to test the changes using real stacks/cli. Also, not sure if I need to add integration test too (didn't see any existing relevant test where I could make some changes).
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license