-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
test('fails if directory not found', () => { | ||
const stack = new cdk.Stack(); | ||
expect(() => new Asset(stack, 'MyDirectory', { | ||
path: '/path/not/found/' + Math.random() * 999999, | ||
})).toThrow(); | ||
})).toThrow(/Cannot find asset/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to
aws-cdk/packages/aws-cdk-lib/core/lib/asset-staging.ts
Lines 174 to 176 in e63c777
if (!fs.existsSync(this.sourcePath)) { | |
throw new Error(`Cannot find asset at ${this.sourcePath}`); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wanted to refine the existing test to help differentiate between the two errors, since I was adding a new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see it now 👍🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @nmussy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!props.path) { | ||
throw new Error('Asset path cannot be empty'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
path
property is not empty.Description of how you validated changes
I've added a test for both the
aws-lambda
package, 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