Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-apprunner-alpha/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
);
}
}
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
);
}
}
Expand Down
32 changes: 16 additions & 16 deletions packages/@aws-cdk/aws-apprunner-alpha/lib/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1019,24 +1019,24 @@ 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 = '/';
}
}

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()}`);
}
}

Expand Down Expand Up @@ -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,
);
}
}
Expand Down Expand Up @@ -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 });
}
Expand All @@ -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 });
Expand Down Expand Up @@ -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) || {};
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-apprunner-alpha/lib/vpc-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const enableNoThrowDefaultErrorIn = [
'aws-applicationautoscaling',
'aws-appsync',
'aws-appmesh',
'aws-apprunner',
'aws-autoscaling',
'aws-autoscaling-common',
'aws-backup',
Expand Down