Skip to content

Commit 21804fd

Browse files
chore(rds): improve error messages for providing a vpc to cluster (#29706)
Just an idea/I was curious. Personally, when I stumbled upon this error I got a bit confused because I wasn't sure what instanceProps was. I think the message 'Provide either vpc or instanceProps.vpc, but not both" provides the same explanation for both cases? Or we rephrase the error message to not use "If instanceProps was provided", because the code can figure whether instanceProps was provided with another if condition Then the message would just be "VPC must be provided". Hence, someone who is unaware of instanceProps, doesn't need to be notified of it. Just an idea though and it's nitpicking! Thoughts? ### Reason for this change Better error message when running into this error ### Description of changes Consolidated logs statements ### Description of how you validated changes I have not validated anything because this was just an idea/I was curious ### 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*
1 parent 213fffc commit 21804fd

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

packages/aws-cdk-lib/aws-rds/lib/cluster.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,8 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase {
595595
constructor(scope: Construct, id: string, props: DatabaseClusterBaseProps) {
596596
super(scope, id);
597597

598-
if ((props.vpc && props.instanceProps?.vpc)) {
598+
if ((props.vpc && props.instanceProps?.vpc) || (!props.vpc && !props.instanceProps?.vpc)) {
599599
throw new Error('Provide either vpc or instanceProps.vpc, but not both');
600-
} else if (!props.vpc && !props.instanceProps?.vpc) {
601-
throw new Error('If instanceProps is not provided then `vpc` must be provided.');
602600
}
603601
if ((props.vpcSubnets && props.instanceProps?.vpcSubnets)) {
604602
throw new Error('Provide either vpcSubnets or instanceProps.vpcSubnets, but not both');

packages/aws-cdk-lib/aws-rds/test/cluster.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('cluster new api', () => {
6767
iamAuthentication: true,
6868
});
6969
// THEN
70-
}).toThrow(/If instanceProps is not provided then `vpc` must be provided./);
70+
}).toThrow(/Provide either vpc or instanceProps.vpc, but not both/);
7171
});
7272

7373
test('when both vpc and instanceProps.vpc are provided', () => {

0 commit comments

Comments
 (0)