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
20 changes: 10 additions & 10 deletions packages/@aws-cdk/aws-neptune-alpha/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as kms from 'aws-cdk-lib/aws-kms';
import * as logs from 'aws-cdk-lib/aws-logs';
import { Aws, Duration, IResource, Lazy, RemovalPolicy, Resource, Token } from 'aws-cdk-lib/core';
import { Aws, Duration, IResource, Lazy, RemovalPolicy, Resource, Token, ValidationError } from 'aws-cdk-lib/core';
import { Construct } from 'constructs';
import { Endpoint } from './endpoint';
import { InstanceType } from './instance';
Expand Down Expand Up @@ -540,7 +540,7 @@ export abstract class DatabaseClusterBase extends Resource implements IDatabaseC

public grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant {
if (this.enableIamAuthentication === false) {
throw new Error('Cannot grant permissions when IAM authentication is disabled');
throw new ValidationError('Cannot grant permissions when IAM authentication is disabled', this);
}

this.enableIamAuthentication = true;
Expand Down Expand Up @@ -643,7 +643,7 @@ export class DatabaseCluster extends DatabaseClusterBase implements IDatabaseClu

// Cannot test whether the subnets are in different AZs, but at least we can test the amount.
if (subnetIds.length < 2) {
throw new Error(`Cluster requires at least 2 subnets, got ${subnetIds.length}`);
throw new ValidationError(`Cluster requires at least 2 subnets, got ${subnetIds.length}`, this);
}

this.subnetGroup = props.subnetGroup ?? new SubnetGroup(this, 'Subnets', {
Expand All @@ -664,15 +664,15 @@ export class DatabaseCluster extends DatabaseClusterBase implements IDatabaseClu
const storageEncrypted = props.storageEncrypted ?? true;

if (props.kmsKey && !storageEncrypted) {
throw new Error('KMS key supplied but storageEncrypted is false');
throw new ValidationError('KMS key supplied but storageEncrypted is false', this);
}

const deletionProtection = props.deletionProtection ?? (props.removalPolicy === RemovalPolicy.RETAIN ? true : undefined);

this.enableIamAuthentication = props.iamAuthentication;

if (props.instanceType === InstanceType.SERVERLESS && !props.serverlessScalingConfiguration) {
throw new Error('You need to specify a serverless scaling configuration with a db.serverless instance type.');
throw new ValidationError('You need to specify a serverless scaling configuration with a db.serverless instance type.', this);
}

this.validateServerlessScalingConfiguration(props.serverlessScalingConfiguration);
Expand Down Expand Up @@ -729,7 +729,7 @@ export class DatabaseCluster extends DatabaseClusterBase implements IDatabaseClu
// Create the instances
const instanceCount = props.instances ?? DatabaseCluster.DEFAULT_NUM_INSTANCES;
if (instanceCount < 1) {
throw new Error('At least one instance is required');
throw new ValidationError('At least one instance is required', this);
}

for (let i = 0; i < instanceCount; i++) {
Expand Down Expand Up @@ -769,14 +769,14 @@ export class DatabaseCluster extends DatabaseClusterBase implements IDatabaseClu
private validateServerlessScalingConfiguration(serverlessScalingConfiguration?: ServerlessScalingConfiguration) {
if (!serverlessScalingConfiguration) return;
if (serverlessScalingConfiguration.minCapacity < 1) {
throw new Error(`ServerlessScalingConfiguration minCapacity must be greater or equal than 1, received ${serverlessScalingConfiguration.minCapacity}`);
throw new ValidationError(`ServerlessScalingConfiguration minCapacity must be greater or equal than 1, received ${serverlessScalingConfiguration.minCapacity}`, this);
}
if (serverlessScalingConfiguration.maxCapacity < 2.5 || serverlessScalingConfiguration.maxCapacity > 128) {
throw new Error(`ServerlessScalingConfiguration maxCapacity must be between 2.5 and 128, received ${serverlessScalingConfiguration.maxCapacity}`);
throw new ValidationError(`ServerlessScalingConfiguration maxCapacity must be between 2.5 and 128, received ${serverlessScalingConfiguration.maxCapacity}`, this);
}
if (serverlessScalingConfiguration.minCapacity >= serverlessScalingConfiguration.maxCapacity) {
throw new Error(`ServerlessScalingConfiguration minCapacity ${serverlessScalingConfiguration.minCapacity} ` +
`must be less than serverlessScalingConfiguration maxCapacity ${serverlessScalingConfiguration.maxCapacity}`);
throw new ValidationError(`ServerlessScalingConfiguration minCapacity ${serverlessScalingConfiguration.minCapacity} ` +
`must be less than serverlessScalingConfiguration maxCapacity ${serverlessScalingConfiguration.maxCapacity}`, this);
}
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-neptune-alpha/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export class InstanceType {
if (cdk.Token.isUnresolved(instanceType) || instanceType.startsWith('db.')) {
this._instanceType = instanceType;
} else {
throw new Error(`instance type must start with 'db.'; (got ${instanceType})`);
throw new cdk.UnscopedValidationError(`instance type must start with 'db.'; (got ${instanceType})`);
}
}
}
Expand Down
Loading