Skip to content

fix(toolkit-lib): guard against a stack with no metadata in countAssemblyResults - #1952

Open
sharonyajain wants to merge 1 commit into
aws:mainfrom
sharonyajain:fix/count-assembly-results-metadata-null-guard
Open

fix(toolkit-lib): guard against a stack with no metadata in countAssemblyResults#1952
sharonyajain wants to merge 1 commit into
aws:mainfrom
sharonyajain:fix/count-assembly-results-metadata-null-guard

Conversation

@sharonyajain

Copy link
Copy Markdown

countAssemblyResults counts annotation error codes after synth by calling Object.values(stack.metadata) for every stack in assembly.stacksRecursively, with no null guard. When a synthesized stack has no metadata (stack.metadata is undefined), Object.values(undefined) throws:

TypeError: Cannot convert undefined or null to object
    at Object.values (<anonymous>)
    at countAssemblyResults (packages/@aws-cdk/toolkit-lib/lib/toolkit/private/count-assembly-results.ts:11)
    at synthAndMeasure (.../toolkit.ts)
    at Toolkit.synth (.../toolkit.ts)

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 whose metadata is 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

  • This change contains a major version upgrade for a dependency and I confirm all breaking changes are addressed
    • Release notes for the new version:

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

…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.
@@ -0,0 +1,51 @@
import { countAssemblyResults } from '../../../lib/toolkit/private/count-assembly-results';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
import { countAssemblyResults } from '../../../lib/toolkit/private/count-assembly-results';
import { countAssemblyResults } from '../../../src/toolkit/private/count-assembly-results';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants