fix: bugs on setGitEnvironmentVariables#598
Closed
fed-sv wants to merge 1 commit into
Closed
Conversation
Author
Author
|
@hari-euka sorry I didn't realize your PR was closed 🤣 |
Author
|
@avangelillo feel free to close this PR if you guys rather go with #597 👍 |
Author
|
add missing link to issue. Fixes #596 |
Contributor
|
Thanks for opening this PR, this was ultimately resolved with #601 and https://github.com/DataDog/datadog-cdk-constructs/releases/tag/v2-4.0.0 |
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.
What does this PR do?
Fixes a
TypeError: Cannot read properties of undefined (reading 'value')crash insetGitEnvironmentVariableswhenDD_TAGSis not already set on the lambda function.Also fixes a minor log message bug in the
gitRepoUrlOverridedebug statement, which was logginghashinstead ofgitRepoUrlas the "instead of" value.Motivation
The
elsebranch of theDD_TAGScheck callslam.addEnvironment(DD_TAGS, ...)to set the sha, then immediately reads backlam.environment[DD_TAGS].valueon the following line to append the repo URL. Becauselam.environmentis a private CDK field accessed viaanycast, this read-back is not guaranteed to reflect the value just written byaddEnvironment- in particular, it fails when there is a CDK peer dependency version mismatch between the consuming project and the version this library was tested against. The result is a hard crash at CDK synth time that completely prevents deployment.The root cause is that the two git tags (
git.commit.shaandgit.repository_url) are set in two separate operations, but the second operation always uses the private field read - even when the first operation went through the publicaddEnvironmentAPI (theelsebranch).Testing Guidelines
Existing unit tests covering
setGitEnvironmentVariablescontinue to pass. The fix is behaviorally identical for the case whereDD_TAGSis already set (private field is read, confirmed non-undefined, then appended to - unchanged). For the case whereDD_TAGSis not yet set, both git tags are now written atomically in a singleaddEnvironmentcall, eliminating the unsafe read-back.Additional Notes
The unconditional line 71 (
lam.environment[DD_TAGS].value += ...) was always unsafe after theelsebranch becauseaddEnvironmentis a public method that may not synchronously update the privateenvironmentmap in all CDK versions. Combining both tags into a single value in both branches removes this assumption entirely.Types of Changes
Check all that apply