@@ -18,6 +18,7 @@ import * as logs from '../../aws-logs';
18
18
import * as s3 from '../../aws-s3' ;
19
19
import * as secretsmanager from '../../aws-secretsmanager' ;
20
20
import { ArnComponents , ArnFormat , Duration , FeatureFlags , IResource , Lazy , RemovalPolicy , Resource , Stack , Token , Tokenization } from '../../core' ;
21
+ import { ValidationError } from '../../core/lib/errors' ;
21
22
import * as cxapi from '../../cx-api' ;
22
23
23
24
/**
@@ -180,15 +181,15 @@ export abstract class DatabaseInstanceBase extends Resource implements IDatabase
180
181
181
182
public grantConnect ( grantee : iam . IGrantable , dbUser ?: string ) : iam . Grant {
182
183
if ( this . enableIamAuthentication === false ) {
183
- throw new Error ( 'Cannot grant connect when IAM authentication is disabled' ) ;
184
+ throw new ValidationError ( 'Cannot grant connect when IAM authentication is disabled' , this ) ;
184
185
}
185
186
186
187
if ( ! this . instanceResourceId ) {
187
- throw new Error ( 'For imported Database Instances, instanceResourceId is required to grantConnect()' ) ;
188
+ throw new ValidationError ( 'For imported Database Instances, instanceResourceId is required to grantConnect()' , this ) ;
188
189
}
189
190
190
191
if ( ! dbUser ) {
191
- throw new Error ( 'For imported Database Instances, the dbUser is required to grantConnect()' ) ;
192
+ throw new ValidationError ( 'For imported Database Instances, the dbUser is required to grantConnect()' , this ) ;
192
193
}
193
194
194
195
this . enableIamAuthentication = true ;
@@ -784,12 +785,12 @@ abstract class DatabaseInstanceNew extends DatabaseInstanceBase implements IData
784
785
785
786
this . vpc = props . vpc ;
786
787
if ( props . vpcSubnets && props . vpcPlacement ) {
787
- throw new Error ( 'Only one of `vpcSubnets` or `vpcPlacement` can be specified' ) ;
788
+ throw new ValidationError ( 'Only one of `vpcSubnets` or `vpcPlacement` can be specified' , this ) ;
788
789
}
789
790
this . vpcPlacement = props . vpcSubnets ?? props . vpcPlacement ;
790
791
791
792
if ( props . multiAz === true && props . availabilityZone ) {
792
- throw new Error ( 'Requesting a specific availability zone is not valid for Multi-AZ instances' ) ;
793
+ throw new ValidationError ( 'Requesting a specific availability zone is not valid for Multi-AZ instances' , this ) ;
793
794
}
794
795
795
796
const subnetGroup = props . subnetGroup ?? new SubnetGroup ( this , 'SubnetGroup' , {
@@ -820,12 +821,12 @@ abstract class DatabaseInstanceNew extends DatabaseInstanceBase implements IData
820
821
const storageType = props . storageType ?? StorageType . GP2 ;
821
822
const iops = defaultIops ( storageType , props . iops ) ;
822
823
if ( props . storageThroughput && storageType !== StorageType . GP3 ) {
823
- throw new Error ( `The storage throughput can only be specified with GP3 storage type. Got ${ storageType } .` ) ;
824
+ throw new ValidationError ( `The storage throughput can only be specified with GP3 storage type. Got ${ storageType } .` , this ) ;
824
825
}
825
826
if ( storageType === StorageType . GP3 && props . storageThroughput && iops
826
827
&& ! Token . isUnresolved ( props . storageThroughput ) && ! Token . isUnresolved ( iops )
827
828
&& props . storageThroughput / iops > 0.25 ) {
828
- throw new Error ( `The maximum ratio of storage throughput to IOPS is 0.25. Got ${ props . storageThroughput / iops } .` ) ;
829
+ throw new ValidationError ( `The maximum ratio of storage throughput to IOPS is 0.25. Got ${ props . storageThroughput / iops } .` , this ) ;
829
830
}
830
831
831
832
this . cloudwatchLogGroups = { } ;
@@ -837,7 +838,7 @@ abstract class DatabaseInstanceNew extends DatabaseInstanceBase implements IData
837
838
const enablePerformanceInsights = props . enablePerformanceInsights
838
839
|| props . performanceInsightRetention !== undefined || props . performanceInsightEncryptionKey !== undefined ;
839
840
if ( enablePerformanceInsights && props . enablePerformanceInsights === false ) {
840
- throw new Error ( '`enablePerformanceInsights` disabled, but `performanceInsightRetention` or `performanceInsightEncryptionKey` was set' ) ;
841
+ throw new ValidationError ( '`enablePerformanceInsights` disabled, but `performanceInsightRetention` or `performanceInsightEncryptionKey` was set' , this ) ;
841
842
}
842
843
843
844
if ( props . domain ) {
@@ -1019,13 +1020,13 @@ abstract class DatabaseInstanceSource extends DatabaseInstanceNew implements IDa
1019
1020
const engineFeatures = engineConfig . features ;
1020
1021
if ( s3ImportRole ) {
1021
1022
if ( ! engineFeatures ?. s3Import ) {
1022
- throw new Error ( `Engine '${ engineDescription ( props . engine ) } ' does not support S3 import` ) ;
1023
+ throw new ValidationError ( `Engine '${ engineDescription ( props . engine ) } ' does not support S3 import` , this ) ;
1023
1024
}
1024
1025
instanceAssociatedRoles . push ( { roleArn : s3ImportRole . roleArn , featureName : engineFeatures ?. s3Import } ) ;
1025
1026
}
1026
1027
if ( s3ExportRole ) {
1027
1028
if ( ! engineFeatures ?. s3Export ) {
1028
- throw new Error ( `Engine '${ engineDescription ( props . engine ) } ' does not support S3 export` ) ;
1029
+ throw new ValidationError ( `Engine '${ engineDescription ( props . engine ) } ' does not support S3 export` , this ) ;
1029
1030
}
1030
1031
// only add the export feature if it's different from the import feature
1031
1032
if ( engineFeatures . s3Import !== engineFeatures ?. s3Export ) {
@@ -1036,7 +1037,7 @@ abstract class DatabaseInstanceSource extends DatabaseInstanceNew implements IDa
1036
1037
this . instanceType = props . instanceType ?? ec2 . InstanceType . of ( ec2 . InstanceClass . M5 , ec2 . InstanceSize . LARGE ) ;
1037
1038
1038
1039
if ( props . parameterGroup && props . parameters ) {
1039
- throw new Error ( 'You cannot specify both parameterGroup and parameters' ) ;
1040
+ throw new ValidationError ( 'You cannot specify both parameterGroup and parameters' , this ) ;
1040
1041
}
1041
1042
1042
1043
const dbParameterGroupName = props . parameters
@@ -1069,13 +1070,13 @@ abstract class DatabaseInstanceSource extends DatabaseInstanceNew implements IDa
1069
1070
*/
1070
1071
public addRotationSingleUser ( options : RotationSingleUserOptions = { } ) : secretsmanager . SecretRotation {
1071
1072
if ( ! this . secret ) {
1072
- throw new Error ( 'Cannot add single user rotation for an instance without secret.' ) ;
1073
+ throw new ValidationError ( 'Cannot add single user rotation for an instance without secret.' , this ) ;
1073
1074
}
1074
1075
1075
1076
const id = 'RotationSingleUser' ;
1076
1077
const existing = this . node . tryFindChild ( id ) ;
1077
1078
if ( existing ) {
1078
- throw new Error ( 'A single user rotation was already added to this instance.' ) ;
1079
+ throw new ValidationError ( 'A single user rotation was already added to this instance.' , this ) ;
1079
1080
}
1080
1081
1081
1082
return new secretsmanager . SecretRotation ( this , id , {
@@ -1092,7 +1093,7 @@ abstract class DatabaseInstanceSource extends DatabaseInstanceNew implements IDa
1092
1093
*/
1093
1094
public addRotationMultiUser ( id : string , options : RotationMultiUserOptions ) : secretsmanager . SecretRotation {
1094
1095
if ( ! this . secret ) {
1095
- throw new Error ( 'Cannot add multi user rotation for an instance without secret.' ) ;
1096
+ throw new ValidationError ( 'Cannot add multi user rotation for an instance without secret.' , this ) ;
1096
1097
}
1097
1098
1098
1099
return new secretsmanager . SecretRotation ( this , id , {
@@ -1115,7 +1116,7 @@ abstract class DatabaseInstanceSource extends DatabaseInstanceNew implements IDa
1115
1116
public grantConnect ( grantee : iam . IGrantable , dbUser ?: string ) : iam . Grant {
1116
1117
if ( ! dbUser ) {
1117
1118
if ( ! this . secret ) {
1118
- throw new Error ( 'A secret or dbUser is required to grantConnect()' ) ;
1119
+ throw new ValidationError ( 'A secret or dbUser is required to grantConnect()' , this ) ;
1119
1120
}
1120
1121
1121
1122
dbUser = this . secret . secretValueFromJson ( 'username' ) . unsafeUnwrap ( ) ;
@@ -1248,7 +1249,7 @@ export class DatabaseInstanceFromSnapshot extends DatabaseInstanceSource impleme
1248
1249
let secret = credentials ?. secret ;
1249
1250
if ( ! secret && credentials ?. generatePassword ) {
1250
1251
if ( ! credentials . username ) {
1251
- throw new Error ( '`credentials` `username` must be specified when `generatePassword` is set to true' ) ;
1252
+ throw new ValidationError ( '`credentials` `username` must be specified when `generatePassword` is set to true' , this ) ;
1252
1253
}
1253
1254
1254
1255
secret = new DatabaseSecret ( this , 'Secret' , {
@@ -1351,7 +1352,7 @@ export class DatabaseInstanceReadReplica extends DatabaseInstanceNew implements
1351
1352
if ( props . sourceDatabaseInstance . engine
1352
1353
&& ! props . sourceDatabaseInstance . engine . supportsReadReplicaBackups
1353
1354
&& props . backupRetention ) {
1354
- throw new Error ( `Cannot set 'backupRetention', as engine '${ engineDescription ( props . sourceDatabaseInstance . engine ) } ' does not support automatic backups for read replicas` ) ;
1355
+ throw new ValidationError ( `Cannot set 'backupRetention', as engine '${ engineDescription ( props . sourceDatabaseInstance . engine ) } ' does not support automatic backups for read replicas` , this ) ;
1355
1356
}
1356
1357
1357
1358
// The read replica instance always uses the same engine as the source instance
0 commit comments