fix(backend-deployer): map toolkit-lib countAssemblyResults crash to a fault - #3343
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 617203c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Author
|
@Simone319 this PR supersedes #3329 (which became un-reopenable after its branch lost common history with main). Both of your review notes from #3329 are addressed here in
|
Simone319
approved these changes
Sep 10, 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.
Problem
npx ampx sandboxandampx pipeline-deploycrash during synth with a generic, misleading error that blames the customer's backend code:Running with
--debugshows the crash is not in the customer'samplify/backend.tsat all — it originates inside@aws-cdk/toolkit-lib:countAssemblyResultscallsObject.values(stack.metadata)with no null guard, and at least one nested stack that a Gen 2 backend (auth + multi-model data + storage) generates hasmetadataundefined — soObject.values(undefined)throws. This is a library bug, not a customer error, butbackend-deployerre-wraps theTypeErrorvia the genericTypeError → SyntaxErrormapping and tells the customer to fix their own backend.Issue number, if available: #3316
Changes
cdk_error_mapper.ts: add a specific branch — placed before the genericTypeErrorbranch — that detects this crash signature (TypeError+Cannot convert undefined or null to object+countAssemblyResultsin the stack) and maps it to a fault (CDKSynthAssemblyMetadataFault) with an accurate, non-blaming message and aresolutionthat points at the upstream bug, instead of a customer-facingSyntaxError. The original error is preserved as the cause.cdk_error_mapper.ts: addCDKSynthAssemblyMetadataFaultto theCDKDeploymentErrorunion so the named fault is consistent with every other error there (review nit).cdk_error_mapper.ts: add aTODOabove the fault branch linking fix(toolkit-lib): guard against a stack with no metadata in countAssemblyResults aws/aws-cdk-cli#1952 — once a@aws-cdk/toolkit-librelease ships the merged null guard and this package bumps its pin,countAssemblyResultsno longer throws and this branch becomes dead code to remove (review nit).Note on scope: this PR only reclassifies the error so customers are no longer told to debug backend code that is not at fault. It does not fix the crash itself — the missing null guard lives in
@aws-cdk/toolkit-liband the actual fix belongs upstream inaws/aws-cdk-cli(Object.values(s.metadata ?? {}), merged in aws/aws-cdk-cli#1952). A@aws-cdk/toolkit-libversion bump was considered but dropped: no published release contains the guard yet, so bumping would not fix the crash, andmaindeliberately pins1.32.0.Supersedes #3329, which became un-reopenable after its head branch lost common history with
mainduring a rebase. This PR is the same branch (fix/toolkit-lib-metadata-null-guard-3316) rebuilt cleanly on currentmain, carrying the original fix plus the two review nits above.Corresponding docs PR, if applicable: N/A
Validation
cdk_error_mapper.test.ts:CDKSynthAssemblyMetadataFaultand is classified as aFAULT(not a customerERROR);TypeErroris preserved as thecause;TypeErrorstill maps to the existing backendSyntaxError(no regression / over-broad match).backend-deployererror-mapper suite: 65/65 pass.tsc --buildonbackend-deployerclean, prettier + eslint clean.getAmplifyErrorexercises the exact mapping path.Checklist
run-e2elabel set.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
no linked-issue close: partially addresses #3316 (improves the error message); the underlying crash fix is upstream in aws/aws-cdk-cli, so this PR intentionally does not close the issue.