Calling cdk diff
from 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.
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?
It returns 0
if there are no differences as documented here:
https://github.com/awslabs/aws-cdk/blob/7001f7723cde611f0d8cd9c182f92120b09579c3/packages/aws-cdk/bin/cdk.ts#L69
and here https://docs.aws.amazon.com/CDK/latest/userguide/tools.html
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.
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 usecdk diff
to check if there is a diff and change the default behavior to what people most expect.