diff --git a/packages/@aws-cdk/aws-apprunner-alpha/.eslintrc.js b/packages/@aws-cdk/aws-apprunner-alpha/.eslintrc.js index b284f20df26e9..0349bd1a34c53 100644 --- a/packages/@aws-cdk/aws-apprunner-alpha/.eslintrc.js +++ b/packages/@aws-cdk/aws-apprunner-alpha/.eslintrc.js @@ -4,5 +4,12 @@ baseConfig.parserOptions.project = __dirname + '/tsconfig.json'; baseConfig.rules['import/no-extraneous-dependencies'] = ['error', { devDependencies: true, peerDependencies: true } ]; baseConfig.rules['import/order'] = 'off'; baseConfig.rules['@aws-cdk/invalid-cfn-imports'] = 'off'; +baseConfig.rules['@cdklabs/no-throw-default-error'] = ['error']; +baseConfig.overrides.push({ + files: ["./test/**"], + rules: { + "@cdklabs/no-throw-default-error": "off", + }, +}); module.exports = baseConfig; diff --git a/packages/@aws-cdk/aws-apprunner-alpha/lib/auto-scaling-configuration.ts b/packages/@aws-cdk/aws-apprunner-alpha/lib/auto-scaling-configuration.ts index 825c3bbc72476..0aa0456859623 100644 --- a/packages/@aws-cdk/aws-apprunner-alpha/lib/auto-scaling-configuration.ts +++ b/packages/@aws-cdk/aws-apprunner-alpha/lib/auto-scaling-configuration.ts @@ -118,7 +118,7 @@ export class AutoScalingConfiguration extends cdk.Resource implements IAutoScali const resourceParts = cdk.Fn.split('/', autoScalingConfigurationArn); if (!resourceParts || resourceParts.length < 3) { - throw new Error(`Unexpected ARN format: ${autoScalingConfigurationArn}.`); + throw new cdk.UnscopedValidationError(`Unexpected ARN format: ${autoScalingConfigurationArn}.`); } const autoScalingConfigurationName = cdk.Fn.select(0, resourceParts); @@ -175,14 +175,14 @@ export class AutoScalingConfiguration extends cdk.Resource implements IAutoScali private validateAutoScalingConfiguration(props: AutoScalingConfigurationProps) { if (props.autoScalingConfigurationName !== undefined && !cdk.Token.isUnresolved(props.autoScalingConfigurationName)) { if (props.autoScalingConfigurationName.length < 4 || props.autoScalingConfigurationName.length > 32) { - throw new Error( - `\`autoScalingConfigurationName\` must be between 4 and 32 characters, got: ${props.autoScalingConfigurationName.length} characters.`, + throw new cdk.ValidationError( + `\`autoScalingConfigurationName\` must be between 4 and 32 characters, got: ${props.autoScalingConfigurationName.length} characters.`, this, ); } if (!/^[A-Za-z0-9][A-Za-z0-9\-_]*$/.test(props.autoScalingConfigurationName)) { - throw new Error( - `\`autoScalingConfigurationName\` must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores after that, got: ${props.autoScalingConfigurationName}.`, + throw new cdk.ValidationError( + `\`autoScalingConfigurationName\` must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores after that, got: ${props.autoScalingConfigurationName}.`, this, ); } } @@ -192,19 +192,19 @@ export class AutoScalingConfiguration extends cdk.Resource implements IAutoScali const isMaxConcurrencyDefined = typeof props.maxConcurrency === 'number'; if (isMinSizeDefined && (props.minSize < 1 || props.minSize > 25)) { - throw new Error(`minSize must be between 1 and 25, got ${props.minSize}.`); + throw new cdk.ValidationError(`minSize must be between 1 and 25, got ${props.minSize}.`, this); } if (isMaxSizeDefined && (props.maxSize < 1 || props.maxSize > 25)) { - throw new Error(`maxSize must be between 1 and 25, got ${props.maxSize}.`); + throw new cdk.ValidationError(`maxSize must be between 1 and 25, got ${props.maxSize}.`, this); } if (isMinSizeDefined && isMaxSizeDefined && !(props.minSize < props.maxSize)) { - throw new Error('maxSize must be greater than minSize.'); + throw new cdk.ValidationError('maxSize must be greater than minSize.', this); } if (isMaxConcurrencyDefined && (props.maxConcurrency < 1 || props.maxConcurrency > 200)) { - throw new Error(`maxConcurrency must be between 1 and 200, got ${props.maxConcurrency}.`); + throw new cdk.ValidationError(`maxConcurrency must be between 1 and 200, got ${props.maxConcurrency}.`, this); } } } diff --git a/packages/@aws-cdk/aws-apprunner-alpha/lib/observability-configuration.ts b/packages/@aws-cdk/aws-apprunner-alpha/lib/observability-configuration.ts index 68f3aad5c7916..b7434d86d85f3 100644 --- a/packages/@aws-cdk/aws-apprunner-alpha/lib/observability-configuration.ts +++ b/packages/@aws-cdk/aws-apprunner-alpha/lib/observability-configuration.ts @@ -104,7 +104,7 @@ export class ObservabilityConfiguration extends cdk.Resource implements IObserva const resourceParts = cdk.Fn.split('/', observabilityConfigurationArn); if (!resourceParts || resourceParts.length < 3) { - throw new Error(`Unexpected ARN format: ${observabilityConfigurationArn}.`); + throw new cdk.UnscopedValidationError(`Unexpected ARN format: ${observabilityConfigurationArn}.`); } const observabilityConfigurationName = cdk.Fn.select(0, resourceParts); @@ -146,14 +146,14 @@ export class ObservabilityConfiguration extends cdk.Resource implements IObserva if (props.observabilityConfigurationName !== undefined && !cdk.Token.isUnresolved(props.observabilityConfigurationName)) { if (props.observabilityConfigurationName.length < 4 || props.observabilityConfigurationName.length > 32) { - throw new Error( - `\`observabilityConfigurationName\` must be between 4 and 32 characters, got: ${props.observabilityConfigurationName.length} characters.`, + throw new cdk.ValidationError( + `\`observabilityConfigurationName\` must be between 4 and 32 characters, got: ${props.observabilityConfigurationName.length} characters.`, this, ); } if (!/^[A-Za-z0-9][A-Za-z0-9\-_]*$/.test(props.observabilityConfigurationName)) { - throw new Error( - `\`observabilityConfigurationName\` must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores after that, got: ${props.observabilityConfigurationName}.`, + throw new cdk.ValidationError( + `\`observabilityConfigurationName\` must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores after that, got: ${props.observabilityConfigurationName}.`, this, ); } } diff --git a/packages/@aws-cdk/aws-apprunner-alpha/lib/service.ts b/packages/@aws-cdk/aws-apprunner-alpha/lib/service.ts index 58aa615222693..52b4993d1c3f1 100644 --- a/packages/@aws-cdk/aws-apprunner-alpha/lib/service.ts +++ b/packages/@aws-cdk/aws-apprunner-alpha/lib/service.ts @@ -73,7 +73,7 @@ export class Cpu { (pattern) => pattern === unit, ); if (!isValidValue) { - throw new Error('CPU value is invalid'); + throw new cdk.UnscopedValidationError('CPU value is invalid'); } return new Cpu(unit); @@ -150,7 +150,7 @@ export class Memory { (pattern) => pattern === unit, ); if (!isValidValue) { - throw new Error('Memory value is invalid'); + throw new cdk.UnscopedValidationError('Memory value is invalid'); } return new Memory(unit); @@ -1019,7 +1019,7 @@ export class HealthCheck { ) { if (this.healthCheckProtocolType === HealthCheckProtocolType.HTTP) { if (this.path !== undefined && this.path.length === 0) { - throw new Error('path length must be greater than 0'); + throw new cdk.UnscopedValidationError('path length must be greater than 0'); } if (this.path === undefined) { this.path = '/'; @@ -1027,16 +1027,16 @@ export class HealthCheck { } if (this.healthyThreshold < 1 || this.healthyThreshold > 20) { - throw new Error(`healthyThreshold must be between 1 and 20, got ${this.healthyThreshold}`); + throw new cdk.UnscopedValidationError(`healthyThreshold must be between 1 and 20, got ${this.healthyThreshold}`); } if (this.unhealthyThreshold < 1 || this.unhealthyThreshold > 20) { - throw new Error(`unhealthyThreshold must be between 1 and 20, got ${this.unhealthyThreshold}`); + throw new cdk.UnscopedValidationError(`unhealthyThreshold must be between 1 and 20, got ${this.unhealthyThreshold}`); } if (this.interval.toSeconds() < 1 || this.interval.toSeconds() > 20) { - throw new Error(`interval must be between 1 and 20 seconds, got ${this.interval.toSeconds()}`); + throw new cdk.UnscopedValidationError(`interval must be between 1 and 20 seconds, got ${this.interval.toSeconds()}`); } if (this.timeout.toSeconds() < 1 || this.timeout.toSeconds() > 20) { - throw new Error(`timeout must be between 1 and 20 seconds, got ${this.timeout.toSeconds()}`); + throw new cdk.UnscopedValidationError(`timeout must be between 1 and 20 seconds, got ${this.timeout.toSeconds()}`); } } @@ -1293,19 +1293,19 @@ export class Service extends cdk.Resource implements IService, iam.IGrantable { if (this.source.codeRepository?.codeConfiguration.configurationSource == ConfigurationSourceType.REPOSITORY && this.source.codeRepository?.codeConfiguration.configurationValues) { - throw new Error('configurationValues cannot be provided if the ConfigurationSource is Repository'); + throw new cdk.ValidationError('configurationValues cannot be provided if the ConfigurationSource is Repository', this); } if (props.serviceName !== undefined && !cdk.Token.isUnresolved(props.serviceName)) { if (props.serviceName.length < 4 || props.serviceName.length > 40) { - throw new Error( - `\`serviceName\` must be between 4 and 40 characters, got: ${props.serviceName.length} characters.`, + throw new cdk.ValidationError( + `\`serviceName\` must be between 4 and 40 characters, got: ${props.serviceName.length} characters.`, this, ); } if (!/^[A-Za-z0-9][A-Za-z0-9\-_]*$/.test(props.serviceName)) { - throw new Error( - `\`serviceName\` must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores after that, got: ${props.serviceName}.`, + throw new cdk.ValidationError( + `\`serviceName\` must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores after that, got: ${props.serviceName}.`, this, ); } } @@ -1384,7 +1384,7 @@ export class Service extends cdk.Resource implements IService, iam.IGrantable { @MethodMetadata() public addEnvironmentVariable(name: string, value: string) { if (name.startsWith('AWSAPPRUNNER')) { - throw new Error(`Environment variable key ${name} with a prefix of AWSAPPRUNNER is not allowed`); + throw new cdk.ValidationError(`Environment variable key ${name} with a prefix of AWSAPPRUNNER is not allowed`, this); } this.variables.push({ name: name, value: value }); } @@ -1395,7 +1395,7 @@ export class Service extends cdk.Resource implements IService, iam.IGrantable { @MethodMetadata() public addSecret(name: string, secret: Secret) { if (name.startsWith('AWSAPPRUNNER')) { - throw new Error(`Environment secret key ${name} with a prefix of AWSAPPRUNNER is not allowed`); + throw new cdk.ValidationError(`Environment secret key ${name} with a prefix of AWSAPPRUNNER is not allowed`, this); } secret.grantRead(this.instanceRole); this.secrets.push({ name: name, value: secret.arn }); @@ -1446,10 +1446,10 @@ export class Service extends cdk.Resource implements IService, iam.IGrantable { ]; if (codeEnv.every(el => el !== undefined) || imageEnv.every(el => el !== undefined)) { - throw new Error([ + throw new cdk.ValidationError([ 'You cannot set both \'environmentVariables\' and \'environment\' properties.', 'Please only use environmentVariables, as environment is deprecated.', - ].join(' ')); + ].join(' '), this); } return codeEnv.find(el => el !== undefined) || imageEnv.find(el => el !== undefined) || {}; diff --git a/packages/@aws-cdk/aws-apprunner-alpha/lib/vpc-connector.ts b/packages/@aws-cdk/aws-apprunner-alpha/lib/vpc-connector.ts index 074b4f48f7ad2..307fb83cc49eb 100644 --- a/packages/@aws-cdk/aws-apprunner-alpha/lib/vpc-connector.ts +++ b/packages/@aws-cdk/aws-apprunner-alpha/lib/vpc-connector.ts @@ -141,14 +141,14 @@ export class VpcConnector extends cdk.Resource implements IVpcConnector { if (props.vpcConnectorName !== undefined && !cdk.Token.isUnresolved(props.vpcConnectorName)) { if (props.vpcConnectorName.length < 4 || props.vpcConnectorName.length > 40) { - throw new Error( - `\`vpcConnectorName\` must be between 4 and 40 characters, got: ${props.vpcConnectorName.length} characters.`, + throw new cdk.ValidationError( + `\`vpcConnectorName\` must be between 4 and 40 characters, got: ${props.vpcConnectorName.length} characters.`, this, ); } if (!/^[A-Za-z0-9][A-Za-z0-9\-_]*$/.test(props.vpcConnectorName)) { - throw new Error( - `\`vpcConnectorName\` must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores after that, got: ${props.vpcConnectorName}.`, + throw new cdk.ValidationError( + `\`vpcConnectorName\` must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores after that, got: ${props.vpcConnectorName}.`, this, ); } } diff --git a/packages/@aws-cdk/aws-apprunner-alpha/lib/vpc-ingress-connection.ts b/packages/@aws-cdk/aws-apprunner-alpha/lib/vpc-ingress-connection.ts index 58054cd9419c2..27f8ddfc60043 100644 --- a/packages/@aws-cdk/aws-apprunner-alpha/lib/vpc-ingress-connection.ts +++ b/packages/@aws-cdk/aws-apprunner-alpha/lib/vpc-ingress-connection.ts @@ -148,14 +148,14 @@ export class VpcIngressConnection extends cdk.Resource implements IVpcIngressCon if (props.vpcIngressConnectionName !== undefined && !cdk.Token.isUnresolved(props.vpcIngressConnectionName)) { if (props.vpcIngressConnectionName.length < 4 || props.vpcIngressConnectionName.length > 40) { - throw new Error( - `\`vpcIngressConnectionName\` must be between 4 and 40 characters, got: ${props.vpcIngressConnectionName.length} characters.`, + throw new cdk.ValidationError( + `\`vpcIngressConnectionName\` must be between 4 and 40 characters, got: ${props.vpcIngressConnectionName.length} characters.`, this, ); } if (!/^[A-Za-z0-9][A-Za-z0-9\-_]*$/.test(props.vpcIngressConnectionName)) { - throw new Error( - `\`vpcIngressConnectionName\` must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores after that, got: ${props.vpcIngressConnectionName}.`, + throw new cdk.ValidationError( + `\`vpcIngressConnectionName\` must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores after that, got: ${props.vpcIngressConnectionName}.`, this, ); } } diff --git a/packages/aws-cdk-lib/.eslintrc.js b/packages/aws-cdk-lib/.eslintrc.js index f86df8e8e501d..8962406736e52 100644 --- a/packages/aws-cdk-lib/.eslintrc.js +++ b/packages/aws-cdk-lib/.eslintrc.js @@ -28,6 +28,7 @@ const enableNoThrowDefaultErrorIn = [ 'aws-applicationautoscaling', 'aws-appsync', 'aws-appmesh', + 'aws-apprunner', 'aws-autoscaling', 'aws-autoscaling-common', 'aws-backup',