@@ -28,7 +28,7 @@ import * as iam from '../../aws-iam';
28
28
import * as kms from '../../aws-kms' ;
29
29
import * as s3 from '../../aws-s3' ;
30
30
import * as secretsmanager from '../../aws-secretsmanager' ;
31
- import { ArnFormat , Aws , Duration , IResource , Lazy , Names , PhysicalName , Reference , Resource , SecretValue , Stack , Token , TokenComparison , Tokenization } from '../../core' ;
31
+ import { ArnFormat , Aws , Duration , IResource , Lazy , Names , PhysicalName , Reference , Resource , SecretValue , Stack , Token , TokenComparison , Tokenization , UnscopedValidationError , ValidationError } from '../../core' ;
32
32
import { addConstructMetadata , MethodMetadata } from '../../core/lib/metadata-resource' ;
33
33
34
34
const VPC_POLICY_SYM = Symbol . for ( '@aws-cdk/aws-codebuild.roleVpcPolicy' ) ;
@@ -275,7 +275,7 @@ abstract class ProjectBase extends Resource implements IProject {
275
275
*/
276
276
public get connections ( ) : ec2 . Connections {
277
277
if ( ! this . _connections ) {
278
- throw new Error ( 'Only VPC-associated Projects have security groups to manage. Supply the "vpc" parameter when creating the Project' ) ;
278
+ throw new ValidationError ( 'Only VPC-associated Projects have security groups to manage. Supply the "vpc" parameter when creating the Project' , this ) ;
279
279
}
280
280
return this . _connections ;
281
281
}
@@ -887,7 +887,7 @@ export class Project extends ProjectBase {
887
887
const fragments = Tokenization . reverseString ( cfnEnvVariable . value ) ;
888
888
for ( const token of fragments . tokens ) {
889
889
if ( token instanceof SecretValue ) {
890
- throw new Error ( `Plaintext environment variable '${ name } ' contains a secret value! ` +
890
+ throw new UnscopedValidationError ( `Plaintext environment variable '${ name } ' contains a secret value! ` +
891
891
'This means the value of this variable will be visible in plain text in the AWS Console. ' +
892
892
"Please consider using CodeBuild's SecretsManager environment variables feature instead. " +
893
893
"If you'd like to continue with having this secret in the plaintext environment variables, " +
@@ -921,7 +921,7 @@ export class Project extends ProjectBase {
921
921
if ( envVariableValue . startsWith ( 'arn:' ) ) {
922
922
const parsedArn = stack . splitArn ( envVariableValue , ArnFormat . COLON_RESOURCE_NAME ) ;
923
923
if ( ! parsedArn . resourceName ) {
924
- throw new Error ( 'SecretManager ARN is missing the name of the secret: ' + envVariableValue ) ;
924
+ throw new UnscopedValidationError ( 'SecretManager ARN is missing the name of the secret: ' + envVariableValue ) ;
925
925
}
926
926
927
927
// the value of the property can be a complex string, separated by ':';
@@ -1077,7 +1077,7 @@ export class Project extends ProjectBase {
1077
1077
this . source = props . source || new NoSource ( ) ;
1078
1078
const sourceConfig = this . source . bind ( this , this ) ;
1079
1079
if ( props . badge && ! this . source . badgeSupported ) {
1080
- throw new Error ( `Badge is not supported for source type ${ this . source . type } ` ) ;
1080
+ throw new ValidationError ( `Badge is not supported for source type ${ this . source . type } ` , this ) ;
1081
1081
}
1082
1082
1083
1083
const artifacts = props . artifacts
@@ -1096,7 +1096,7 @@ export class Project extends ProjectBase {
1096
1096
const environmentVariables = props . environmentVariables || { } ;
1097
1097
const buildSpec = props . buildSpec ;
1098
1098
if ( this . source . type === NO_SOURCE_TYPE && ( buildSpec === undefined || ! buildSpec . isImmediate ) ) {
1099
- throw new Error ( "If the Project's source is NoSource, you need to provide a concrete buildSpec" ) ;
1099
+ throw new ValidationError ( "If the Project's source is NoSource, you need to provide a concrete buildSpec" , this ) ;
1100
1100
}
1101
1101
1102
1102
this . _secondarySources = [ ] ;
@@ -1119,7 +1119,7 @@ export class Project extends ProjectBase {
1119
1119
1120
1120
if ( ! Token . isUnresolved ( props . autoRetryLimit ) && ( props . autoRetryLimit !== undefined ) ) {
1121
1121
if ( props . autoRetryLimit < 0 || props . autoRetryLimit > 10 ) {
1122
- throw new Error ( `autoRetryLimit must be a value between 0 and 10, got ${ props . autoRetryLimit } .` ) ;
1122
+ throw new ValidationError ( `autoRetryLimit must be a value between 0 and 10, got ${ props . autoRetryLimit } .` , this ) ;
1123
1123
}
1124
1124
}
1125
1125
@@ -1252,7 +1252,7 @@ export class Project extends ProjectBase {
1252
1252
@MethodMetadata ( )
1253
1253
public addSecondarySource ( secondarySource : ISource ) : void {
1254
1254
if ( ! secondarySource . identifier ) {
1255
- throw new Error ( 'The identifier attribute is mandatory for secondary sources' ) ;
1255
+ throw new ValidationError ( 'The identifier attribute is mandatory for secondary sources' , this ) ;
1256
1256
}
1257
1257
const secondarySourceConfig = secondarySource . bind ( this , this ) ;
1258
1258
this . _secondarySources . push ( secondarySourceConfig . sourceProperty ) ;
@@ -1284,7 +1284,7 @@ export class Project extends ProjectBase {
1284
1284
@MethodMetadata ( )
1285
1285
public addSecondaryArtifact ( secondaryArtifact : IArtifacts ) : void {
1286
1286
if ( ! secondaryArtifact . identifier ) {
1287
- throw new Error ( 'The identifier attribute is mandatory for secondary artifacts' ) ;
1287
+ throw new ValidationError ( 'The identifier attribute is mandatory for secondary artifacts' , this ) ;
1288
1288
}
1289
1289
this . _secondaryArtifacts . push ( secondaryArtifact . bind ( this , this ) . artifactsProperty ) ;
1290
1290
}
@@ -1372,7 +1372,7 @@ export class Project extends ProjectBase {
1372
1372
errors . push ( ...this . validateLambdaBuildImage ( this . buildImage , props ) ) ;
1373
1373
1374
1374
if ( errors . length > 0 ) {
1375
- throw new Error ( 'Invalid CodeBuild environment: ' + errors . join ( '\n' ) ) ;
1375
+ throw new ValidationError ( 'Invalid CodeBuild environment: ' + errors . join ( '\n' ) , this ) ;
1376
1376
}
1377
1377
1378
1378
const imagePullPrincipalType = this . isLambdaBuildImage ( this . buildImage ) ? undefined :
@@ -1449,7 +1449,7 @@ export class Project extends ProjectBase {
1449
1449
1450
1450
// If the fleetArn is resolved, the fleet is imported and we cannot validate the environment type
1451
1451
if ( Token . isUnresolved ( fleet . fleetArn ) && this . buildImage . type !== fleet . environmentType ) {
1452
- throw new Error ( `The environment type of the fleet (${ fleet . environmentType } ) must match the environment type of the build image (${ this . buildImage . type } )` ) ;
1452
+ throw new ValidationError ( `The environment type of the fleet (${ fleet . environmentType } ) must match the environment type of the build image (${ this . buildImage . type } )` , this ) ;
1453
1453
}
1454
1454
1455
1455
return { fleetArn : fleet . fleetArn } ;
@@ -1463,13 +1463,13 @@ export class Project extends ProjectBase {
1463
1463
*/
1464
1464
private configureVpc ( props : ProjectProps ) : CfnProject . VpcConfigProperty | undefined {
1465
1465
if ( ( props . securityGroups || props . allowAllOutbound !== undefined ) && ! props . vpc ) {
1466
- throw new Error ( 'Cannot configure \'securityGroup\' or \'allowAllOutbound\' without configuring a VPC' ) ;
1466
+ throw new ValidationError ( 'Cannot configure \'securityGroup\' or \'allowAllOutbound\' without configuring a VPC' , this ) ;
1467
1467
}
1468
1468
1469
1469
if ( ! props . vpc ) { return undefined ; }
1470
1470
1471
1471
if ( ( props . securityGroups && props . securityGroups . length > 0 ) && props . allowAllOutbound !== undefined ) {
1472
- throw new Error ( 'Configure \'allowAllOutbound\' directly on the supplied SecurityGroup.' ) ;
1472
+ throw new ValidationError ( 'Configure \'allowAllOutbound\' directly on the supplied SecurityGroup.' , this ) ;
1473
1473
}
1474
1474
1475
1475
let securityGroups : ec2 . ISecurityGroup [ ] ;
@@ -1515,7 +1515,7 @@ export class Project extends ProjectBase {
1515
1515
const status = ( cloudWatchLogs . enabled ?? true ) ? 'ENABLED' : 'DISABLED' ;
1516
1516
1517
1517
if ( status === 'ENABLED' && ! ( cloudWatchLogs . logGroup ) ) {
1518
- throw new Error ( 'Specifying a LogGroup is required if CloudWatch logging for CodeBuild is enabled' ) ;
1518
+ throw new ValidationError ( 'Specifying a LogGroup is required if CloudWatch logging for CodeBuild is enabled' , this ) ;
1519
1519
}
1520
1520
cloudWatchLogs . logGroup ?. grantWrite ( this ) ;
1521
1521
@@ -1591,7 +1591,7 @@ export class Project extends ProjectBase {
1591
1591
if ( ( sourceType === CODEPIPELINE_SOURCE_ARTIFACTS_TYPE ||
1592
1592
artifactsType === CODEPIPELINE_SOURCE_ARTIFACTS_TYPE ) &&
1593
1593
( sourceType !== artifactsType ) ) {
1594
- throw new Error ( 'Both source and artifacts must be set to CodePipeline' ) ;
1594
+ throw new ValidationError ( 'Both source and artifacts must be set to CodePipeline' , this ) ;
1595
1595
}
1596
1596
}
1597
1597
0 commit comments