fix(s3-assets): throw if path property is empty#29425
Conversation
| if (!props.path) { | ||
| throw new Error('Asset path cannot be empty'); | ||
| } |
There was a problem hiding this comment.
It might also be a good idea to check that cdk.out is excluded from the asset source, as Code.fromAsset('.') would cause the same reported issue.
There was a problem hiding this comment.
Good call out, I'm good with the changes in this PR so I'll approve for now but feel free to add that check in a separate PR.
aws-cdk-automation
left a comment
There was a problem hiding this comment.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.
|
Exemption Request: This is just an additional property constraint, a unit test should be sufficient |
|
This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week. |
| expect(() => new Asset(stack, 'MyDirectory', { | ||
| path: '/path/not/found/' + Math.random() * 999999, | ||
| })).toThrow(); | ||
| })).toThrow(/Cannot find asset/); |
There was a problem hiding this comment.
this just throws inherently, correct? Possible to catch this in asset.ts and add the path: Cannot find asset at path: <path> ?
There was a problem hiding this comment.
similar to
aws-cdk/packages/aws-cdk-lib/core/lib/asset-staging.ts
Lines 174 to 176 in e63c777
There was a problem hiding this comment.
I just wanted to refine the existing test to help differentiate between the two errors, since I was adding a new one.
| if (!props.path) { | ||
| throw new Error('Asset path cannot be empty'); | ||
| } |
There was a problem hiding this comment.
Good call out, I'm good with the changes in this PR so I'll approve for now but feel free to add that check in a separate PR.
|
@Mergifyio update |
✅ Branch has been successfully updated |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Issue # (if applicable)
Closes #29410.
Reason for this change
It was reported that a
Code.fromAsset('')was creating an infinite loop by including itself throughcdk.out. This is caused by the following line:aws-cdk/packages/aws-cdk-lib/aws-s3-assets/lib/asset.ts
Line 145 in 730fe63
If an empty string is given to
path.resolve(), the current working directory is returned.Description of changes
I've added a check that verifies that the given
pathproperty is not empty.Description of how you validated changes
I've added a test for both the
aws-lambdapackage, where the issue was originally reported, andaws-s3-assets, where the fix was implementedChecklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license