Skip to content

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

Merged
mrgrain merged 1 commit into
aws:mainfrom
sharonyajain:fix/count-assembly-results-metadata-null-guard
Sep 9, 2026
Merged

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

Conversation

@sharonyajain

Copy link
Copy Markdown
Contributor

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

Comment thread packages/@aws-cdk/toolkit-lib/test/toolkit/count-assembly-results.test.ts Outdated
auto-merge was automatically disabled September 9, 2026 09:37

Head branch was pushed to by a user without write access

…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
sharonyajain force-pushed the fix/count-assembly-results-metadata-null-guard branch from 03452ff to 8f1e39e Compare September 9, 2026 09:56
@sharonyajain
sharonyajain deployed to integ-approval September 9, 2026 09:56 — with GitHub Actions Active
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.32%. Comparing base (f2f4d60) to head (8f1e39e).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1952      +/-   ##
==========================================
- Coverage   91.33%   91.32%   -0.02%     
==========================================
  Files          79       79              
  Lines       12164    12216      +52     
  Branches     1721     1724       +3     
==========================================
+ Hits        11110    11156      +46     
- Misses       1019     1025       +6     
  Partials       35       35              
Flag Coverage Δ
suite.unit 91.32% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

3 participants