fix(toolkit-lib): guard against a stack with no metadata in countAssemblyResults - #1952
Open
sharonyajain wants to merge 1 commit into
Open
Conversation
…mblyResults
countAssemblyResults calls Object.values(stack.metadata) with no null guard while counting annotation error codes after synth. When a synthesized stack has no metadata (stack.metadata is undefined), Object.values(undefined) throws 'Cannot convert undefined or null to object', crashing Toolkit.synth() for otherwise-valid apps.
Guard with 'stack.metadata ?? {}' and add a regression test covering both the undefined-metadata case and the normal annotation-counting path.
sharonyajain
had a problem deploying
to
integ-approval
September 8, 2026 11:40 — with
GitHub Actions
Failure
aws-cdk-automation
enabled auto-merge
September 8, 2026 11:40
mrgrain
approved these changes
Sep 8, 2026
4 tasks
mrgrain
reviewed
Sep 9, 2026
| @@ -0,0 +1,51 @@ | |||
| import { countAssemblyResults } from '../../../lib/toolkit/private/count-assembly-results'; | |||
Contributor
There was a problem hiding this comment.
Suggested change
| import { countAssemblyResults } from '../../../lib/toolkit/private/count-assembly-results'; | |
| import { countAssemblyResults } from '../../../src/toolkit/private/count-assembly-results'; |
mrgrain
requested changes
Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
countAssemblyResultscounts annotation error codes after synth by callingObject.values(stack.metadata)for every stack inassembly.stacksRecursively, with no null guard. When a synthesized stack has no metadata (stack.metadataisundefined),Object.values(undefined)throws:This crashes
Toolkit.synth()for otherwise-valid apps. It was reported downstream in AWS Amplify Gen 2, where a backend defining auth + a multi-model data schema + storage produces at least one nested stack whosemetadatais undefined: aws-amplify/amplify-backend#3316.This change guards the access with
stack.metadata ?? {}(one line) and adds a regression test covering both the undefined-metadata case and the normal annotation-counting path.Fixes #
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license