Aws-cdk: "cdk diff" returns error code 1

Created on 28 Mar 2019  路  7Comments  路  Source: aws/aws-cdk

Calling cdk difffrom NPM fails because the command does not return 0.

package.json

  "scripts": {
    "diff": "cdk diff"    
  }

Running npm run diff fails.

cdk diff; echo $?shows the error code returned is 1.

feature-request packagtools

Most helpful comment

As much as this is a nice a pure way to express that "there is a diff". I doesn't seem like that's what people expect. This is the 3rd or 4th time someone fell into this little pit. I'd argue that we can add a flag --fail for those brave souls who are interested to use cdk diff to check if there is a diff and change the default behavior to what people most expect.

All 7 comments

A workaround to get rid of the `npm ERR! ...:

package.json

  "scripts": {
    "diff": "cdk diff || true"    
  }

Is this enough of an issue to document? Or are we going to try to make it return 0?

As much as this is a nice a pure way to express that "there is a diff". I doesn't seem like that's what people expect. This is the 3rd or 4th time someone fell into this little pit. I'd argue that we can add a flag --fail for those brave souls who are interested to use cdk diff to check if there is a diff and change the default behavior to what people most expect.

For scripts which rely on the error code from cdk diff, there is no way to know if this is due to diffs or some other error (e.g. invalid python code). The flag seems quite appropriate. This is how git does it as well.

git diff --name-only
echo $? # returns 0 

git diff --name-only --exit-code
echo $? # returns 1 if there are diffs

Any updates?

Any updates?

Will open a PR for this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

v-do picture v-do  路  3Comments

ababra picture ababra  路  3Comments

eladb picture eladb  路  3Comments

peterdeme picture peterdeme  路  3Comments

EduardTheThird picture EduardTheThird  路  3Comments