aws / aws/aws-cdk-cli

(toolkit-lib): AssertionError [ERR_ASSERTION]: oldValue and newValue are both undefined!

Open
#390 5 comments 0 reactions 0 assignees View on GitHub
aws-cdk bug effort/medium p2
Dominant language
TypeScript
Stars
105
Forks
122
Avg merge
1d 17h
Merged PRs (30d)
71

Description

### Describe the bug

I have a script that:
1. Imports my CDK app and runs `app.synth()`
2. Creates a `Toolkit` and does `toolkit.fromAssemblyDirectory(app.outdir)`
3. Runs `toolkit.diff()`

The last one crashes with:

```
AssertionError [ERR_ASSERTION]: oldValue and newValue are both undefined!
at new AssertionError (node:internal/assert/assertion_error:452:5)
at Difference (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff/types.ts:344:13)
at (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff/template-and-changeset-diff-merger.ts:131:19)
at ResourceDifference.forEachDifference (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff/types.ts:732:7)
at TemplateAndChangeSetDiffMerger.overrideDiffResourceChangeImpactWithChangeSetChangeImpact (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff/template-and-changeset-diff-merger.ts:102:7)
at (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff-template.ts:61:21)
at (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff/types.ts:451:26)
at Array.forEach ()
at DifferenceCollection.forEachDifference (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff/types.ts:451:13)
at fullDiff (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff-template.ts:60:23) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: undefined,
expected: undefined,
operator: undefined
}
```

I placed a `console.log` into `TemplateAndChangeSetDiffMerger.overrideDiffResourceChangeImpactWithChangeSetChangeImpact` and these are the differences:

```
✨ Synthesis time: 0.01s
start: Building UptoolPersonal-jaka Template
success: Built UptoolPersonal-jaka Template
start: Publishing UptoolPersonal-jaka Template (248189938188-us-east-1)
success: Published UptoolPersonal-jaka Template (248189938188-us-east-1)
Hold on while we create a read-only change set to get a diff with accurate replacement information (use --no-change-set to use a less accurate but faster template-only diff)
CDKMetadata ResourceDifference {
oldValue: {
Type: 'AWS::CDK::Metadata',
Properties: {
Analytics: 'v2:deflate64:H4sIAAAAAAAA/y3MQQ7CIBAF0LN0D2OoC3VpvAEewCDFZtoykzBUEwl3F62r//9b/B7MYQ99516i/TDrBe9Qrtn5WTW6FU6jI3y7jEwClwedveeVshLh3xTBkWJogi5CsbwE1fybtSobhNfkN/r3qoiHAJPsnuYI5gSmmwRRp3aLMYDd8gNi9CmPmgAAAA=='
},
Metadata: { 'aws:cdk:path': 'UptoolPersonal-jaka/CDKMetadata/Default' }
},
newValue: undefined,
resourceTypes: { oldType: 'AWS::CDK::Metadata', newType: undefined },
propertyDiffs: {},
otherDiffs: {},
isAddition: false,
isRemoval: true,
isImport: undefined
}
Account ResourceDifference {
oldValue: {
Type: 'AWS::Organizations::Account',
Properties: { AccountName: 'uptool-personal-jaka', Email: 'jaka@uptool.com' },
DeletionPolicy: 'Delete',
Metadata: { 'aws:cdk:path': 'UptoolPersonal-jaka/Account' }
},
newValue: {
Type: 'AWS::Organizations::Account',
Properties: { AccountName: 'uptool-personal-jaka', Email: 'jaka@uptool.com' },
DeletionPolicy: 'Delete'
},
resourceTypes: {
oldType: 'AWS::Organizations::Account',
newType: 'AWS::Organizations::Account'
},
propertyDiffs: {
AccountName: PropertyDifference {
oldValue: 'uptool-personal-jaka',
newValue: 'uptool-personal-jaka',
isDifferent: false,
changeImpact: 'NO_CHANGE'
},
Email: PropertyDifference {
oldValue: 'jaka@uptool.com',
newValue: 'jaka@uptool.com',
isDifferent: false,
changeImpact: 'NO_CHANGE'
}
},
otherDiffs: {
Type: Difference {
oldValue: 'AWS::Organizations::Account',
newValue: 'AWS::Organizations::Account',
isDifferent: false
},
DeletionPolicy: Difference {
oldValue: 'Delete',
newValue: 'Delete',
isDifferent: false
},
Metadata: Difference {
oldValue: [Object],
newValue: undefined,
isDifferent: true
}
},
isAddition: false,
isRemoval: false,
isImport: undefined
}
node:internal/process/esm_loader:40
internalBinding('errors').triggerUncaughtException(
^

AssertionError [ERR_ASSERTION]: oldValue and newValue are both undefined!
at new AssertionError (node:internal/assert/assertion_error:452:5)
at Difference (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff/types.ts:344:13)
at (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff/template-and-changeset-diff-merger.ts:131:19)
at ResourceDifference.forEachDifference (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff/types.ts:732:7)
at TemplateAndChangeSetDiffMerger.overrideDiffResourceChangeImpactWithChangeSetChangeImpact (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff/template-and-changeset-diff-merger.ts:102:7)
at (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff-template.ts:61:21)
at (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff/types.ts:451:26)
at Array.forEach ()
at DifferenceCollection.forEachDifference (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff/types.ts:451:13)
at fullDiff (/workspaces/aws-org/node_modules/@aws-cdk/cloudformation-diff/lib/diff-template.ts:60:23) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: undefined,
expected: undefined,
operator: undefined
}
```

I have no idea why it's suggesting the removal of metadata or whether that is expected or not.

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Last Known Working CDK Version

_No response_

### Expected Behavior

Not crash.

### Current Behavior

Crash.

### Reproduction Steps

Sorry, no time for self-contained repro. Worked around the issue by calling the `cdk` CLI. I understand that this might make the bug report useless, but posting regardless in case it's obvious to you.

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

@aws-cdk/toolkit-lib 0.3.1 | aws-cdk-lib 2.189.1 | not using CLI for this

### Framework Version

_No response_

### Node.js Version

v18.19.1

### OS

Linux

### Language

TypeScript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.