-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(assertions): throw error or warn when
synth
is called multiple …
…times on mutated construct tree (#31865) Closes #24689 ### Reason for this change Calling `Template.fromStack(stack)` twice on the same stack object will throw the error `Unable to find artifact with id` if the stack is mutated after the first `Template.fromStack(stack)` call. This is because synth should only be called once - from the comment on the `synth` function: > _Once an assembly has been synthesized, it cannot be modified. Subsequent calls will return the same assembly._ Second call of `Template.fromStack(stack)` tries to find the mutated stack since `app.synth()` caches and returns the assembly from the first synth call. ### Description of changes This PR checks to see whether or not the construct tree has been each time `synth()` is called - if it has, then we either throw an error or a warning. We will only throw a warning if synth is being called from `process.once('beforeExit')`. ### Description of how you validated changes Unit test with the customer's same example case, asserting than an error is thrown when synth is called twice after a stack has been mutated after the first synth call. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
46e51f5
commit a261c9d
Showing
4 changed files
with
107 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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