@@ -28,7 +28,7 @@ import * as iam from '../../aws-iam';
2828import * as kms from '../../aws-kms' ;
2929import * as s3 from '../../aws-s3' ;
3030import * 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' ;
3232import { addConstructMetadata , MethodMetadata } from '../../core/lib/metadata-resource' ;
3333
3434const VPC_POLICY_SYM = Symbol . for ( '@aws-cdk/aws-codebuild.roleVpcPolicy' ) ;
@@ -275,7 +275,7 @@ abstract class ProjectBase extends Resource implements IProject {
275275 */
276276 public get connections ( ) : ec2 . Connections {
277277 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 ) ;
279279 }
280280 return this . _connections ;
281281 }
@@ -887,7 +887,7 @@ export class Project extends ProjectBase {
887887 const fragments = Tokenization . reverseString ( cfnEnvVariable . value ) ;
888888 for ( const token of fragments . tokens ) {
889889 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! ` +
891891 'This means the value of this variable will be visible in plain text in the AWS Console. ' +
892892 "Please consider using CodeBuild's SecretsManager environment variables feature instead. " +
893893 "If you'd like to continue with having this secret in the plaintext environment variables, " +
@@ -921,7 +921,7 @@ export class Project extends ProjectBase {
921921 if ( envVariableValue . startsWith ( 'arn:' ) ) {
922922 const parsedArn = stack . splitArn ( envVariableValue , ArnFormat . COLON_RESOURCE_NAME ) ;
923923 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 ) ;
925925 }
926926
927927 // the value of the property can be a complex string, separated by ':';
@@ -1077,7 +1077,7 @@ export class Project extends ProjectBase {
10771077 this . source = props . source || new NoSource ( ) ;
10781078 const sourceConfig = this . source . bind ( this , this ) ;
10791079 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 ) ;
10811081 }
10821082
10831083 const artifacts = props . artifacts
@@ -1096,7 +1096,7 @@ export class Project extends ProjectBase {
10961096 const environmentVariables = props . environmentVariables || { } ;
10971097 const buildSpec = props . buildSpec ;
10981098 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 ) ;
11001100 }
11011101
11021102 this . _secondarySources = [ ] ;
@@ -1119,7 +1119,7 @@ export class Project extends ProjectBase {
11191119
11201120 if ( ! Token . isUnresolved ( props . autoRetryLimit ) && ( props . autoRetryLimit !== undefined ) ) {
11211121 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 ) ;
11231123 }
11241124 }
11251125
@@ -1252,7 +1252,7 @@ export class Project extends ProjectBase {
12521252 @MethodMetadata ( )
12531253 public addSecondarySource ( secondarySource : ISource ) : void {
12541254 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 ) ;
12561256 }
12571257 const secondarySourceConfig = secondarySource . bind ( this , this ) ;
12581258 this . _secondarySources . push ( secondarySourceConfig . sourceProperty ) ;
@@ -1284,7 +1284,7 @@ export class Project extends ProjectBase {
12841284 @MethodMetadata ( )
12851285 public addSecondaryArtifact ( secondaryArtifact : IArtifacts ) : void {
12861286 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 ) ;
12881288 }
12891289 this . _secondaryArtifacts . push ( secondaryArtifact . bind ( this , this ) . artifactsProperty ) ;
12901290 }
@@ -1372,7 +1372,7 @@ export class Project extends ProjectBase {
13721372 errors . push ( ...this . validateLambdaBuildImage ( this . buildImage , props ) ) ;
13731373
13741374 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 ) ;
13761376 }
13771377
13781378 const imagePullPrincipalType = this . isLambdaBuildImage ( this . buildImage ) ? undefined :
@@ -1449,7 +1449,7 @@ export class Project extends ProjectBase {
14491449
14501450 // If the fleetArn is resolved, the fleet is imported and we cannot validate the environment type
14511451 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 ) ;
14531453 }
14541454
14551455 return { fleetArn : fleet . fleetArn } ;
@@ -1463,13 +1463,13 @@ export class Project extends ProjectBase {
14631463 */
14641464 private configureVpc ( props : ProjectProps ) : CfnProject . VpcConfigProperty | undefined {
14651465 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 ) ;
14671467 }
14681468
14691469 if ( ! props . vpc ) { return undefined ; }
14701470
14711471 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 ) ;
14731473 }
14741474
14751475 let securityGroups : ec2 . ISecurityGroup [ ] ;
@@ -1515,7 +1515,7 @@ export class Project extends ProjectBase {
15151515 const status = ( cloudWatchLogs . enabled ?? true ) ? 'ENABLED' : 'DISABLED' ;
15161516
15171517 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 ) ;
15191519 }
15201520 cloudWatchLogs . logGroup ?. grantWrite ( this ) ;
15211521
@@ -1591,7 +1591,7 @@ export class Project extends ProjectBase {
15911591 if ( ( sourceType === CODEPIPELINE_SOURCE_ARTIFACTS_TYPE ||
15921592 artifactsType === CODEPIPELINE_SOURCE_ARTIFACTS_TYPE ) &&
15931593 ( 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 ) ;
15951595 }
15961596 }
15971597
0 commit comments