Skip to content
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

chore: Document return behavior of cdk diff #1446

Merged
merged 1 commit into from
Jan 7, 2019

Conversation

RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented Dec 28, 2018

The cdk diff command intentionally returns non-zero when a difference is found,
similar to how the POSIX diff command behaves (returning 0 when no difference is
found, 1 when some difference is found, and >1 when an error occurred). This
behavior was however undocumented, possibly leading to user confusion.

This change adds a note in cdk --help that mentions the exit code 1 will be used
when a difference is found.

Fixes #1440


Pull Request Checklist

  • Testing
    • Unit test added
    • CLI change?: manually run integration tests and paste output as a PR comment
    • cdk-init template change?: coordinated update of integration tests with team
  • Docs
    • jsdocs: All public APIs documented
    • README: README and/or documentation topic updated
  • Title and Description
    • Change type: title prefixed with fix, feat will appear in changelog
    • Title: use lower-case and doesn't end with a period
    • Breaking?: last paragraph: "BREAKING CHANGE: <describe what changed + link for details>"
    • Issues: Indicate issues fixed via: "Fixes #xxx" or "Closes #xxx"
  • Sensitive Modules (requires 2 PR approvers)
    • IAM Policy Document (in @aws-cdk/aws-iam)
    • EC2 Security Groups and ACLs (in @aws-cdk/aws-ec2)
    • Grant APIs (only if not based on official documentation with a reference)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.

The `cdk diff` command intentionally returns non-zero when a difference is found,
similar to how the POSIX `diff` command behaves (returning 0 when no difference is
found, 1 when some difference is found, and >1 when an error occurred). This
behavior was however undocumented, possibly leading to user confusion.

This change adds a note in `cdk --help` that mentions the exit code 1 will be used
when a difference is found.
@RomainMuller RomainMuller requested a review from a team as a code owner December 28, 2018 09:43
@@ -58,7 +58,7 @@ async function parseCommandLineArguments() {
.option('require-approval', { type: 'string', choices: [RequireApproval.Never, RequireApproval.AnyChange, RequireApproval.Broadening], desc: 'what security-sensitive changes need manual approval' }))
.command('destroy [STACKS..]', 'Destroy the stack(s) named STACKS', yargs => yargs
.option('force', { type: 'boolean', alias: 'f', desc: 'Do not ask for confirmation before destroying the stacks' }))
.command('diff [STACK]', 'Compares the specified stack with the deployed stack or a local template file', yargs => yargs
.command('diff [STACK]', 'Compares the specified stack with the deployed stack or a local template file, and returns with status 1 if any difference is found', yargs => yargs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just say nonzero? That gives us some leeway to use exit codes for different cases?

Copy link
Contributor Author

@RomainMuller RomainMuller Jan 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to specifically mirror the behavior of the POSIX diff, which is to return 1 if a difference is found, 0 if no difference is found, and some other value if an error occurred. It might actually be useful for users to be able to differentiate "failed" from "diff found", which justifies the strictness of the return code.

@RomainMuller RomainMuller merged commit b61c7c9 into master Jan 7, 2019
@RomainMuller RomainMuller deleted the rmuller/diff-result branch January 7, 2019 09:23
@NGL321 NGL321 added the contribution/core This is a PR that came from AWS. label Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cdk diff should not exit with error code in case there is a diff
3 participants