Skip to content

Commit 832eed8

Browse files
chore(neptune-alpha): use typed error (#35960)
### Issue # (if applicable) Relates #32569 ### Reason for this change Throw typed errors everywhere. ### Description of changes - add typed error for neptune alpha module ### Describe any new or updated permissions being added n/a ### Description of how you validated changes Existing tests. Exemptions granted as this is a refactor of existing code. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 93af887 commit 832eed8

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

packages/@aws-cdk/aws-neptune-alpha/lib/cluster.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2';
33
import * as iam from 'aws-cdk-lib/aws-iam';
44
import * as kms from 'aws-cdk-lib/aws-kms';
55
import * as logs from 'aws-cdk-lib/aws-logs';
6-
import { Aws, Duration, IResource, Lazy, RemovalPolicy, Resource, Token } from 'aws-cdk-lib/core';
6+
import { Aws, Duration, IResource, Lazy, RemovalPolicy, Resource, Token, ValidationError } from 'aws-cdk-lib/core';
77
import { Construct } from 'constructs';
88
import { Endpoint } from './endpoint';
99
import { InstanceType } from './instance';
@@ -540,7 +540,7 @@ export abstract class DatabaseClusterBase extends Resource implements IDatabaseC
540540

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

546546
this.enableIamAuthentication = true;
@@ -643,7 +643,7 @@ export class DatabaseCluster extends DatabaseClusterBase implements IDatabaseClu
643643

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

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

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

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

672672
this.enableIamAuthentication = props.iamAuthentication;
673673

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

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

735735
for (let i = 0; i < instanceCount; i++) {
@@ -769,14 +769,14 @@ export class DatabaseCluster extends DatabaseClusterBase implements IDatabaseClu
769769
private validateServerlessScalingConfiguration(serverlessScalingConfiguration?: ServerlessScalingConfiguration) {
770770
if (!serverlessScalingConfiguration) return;
771771
if (serverlessScalingConfiguration.minCapacity < 1) {
772-
throw new Error(`ServerlessScalingConfiguration minCapacity must be greater or equal than 1, received ${serverlessScalingConfiguration.minCapacity}`);
772+
throw new ValidationError(`ServerlessScalingConfiguration minCapacity must be greater or equal than 1, received ${serverlessScalingConfiguration.minCapacity}`, this);
773773
}
774774
if (serverlessScalingConfiguration.maxCapacity < 2.5 || serverlessScalingConfiguration.maxCapacity > 128) {
775-
throw new Error(`ServerlessScalingConfiguration maxCapacity must be between 2.5 and 128, received ${serverlessScalingConfiguration.maxCapacity}`);
775+
throw new ValidationError(`ServerlessScalingConfiguration maxCapacity must be between 2.5 and 128, received ${serverlessScalingConfiguration.maxCapacity}`, this);
776776
}
777777
if (serverlessScalingConfiguration.minCapacity >= serverlessScalingConfiguration.maxCapacity) {
778-
throw new Error(`ServerlessScalingConfiguration minCapacity ${serverlessScalingConfiguration.minCapacity} ` +
779-
`must be less than serverlessScalingConfiguration maxCapacity ${serverlessScalingConfiguration.maxCapacity}`);
778+
throw new ValidationError(`ServerlessScalingConfiguration minCapacity ${serverlessScalingConfiguration.minCapacity} ` +
779+
`must be less than serverlessScalingConfiguration maxCapacity ${serverlessScalingConfiguration.maxCapacity}`, this);
780780
}
781781
}
782782
}

packages/@aws-cdk/aws-neptune-alpha/lib/instance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ export class InstanceType {
300300
if (cdk.Token.isUnresolved(instanceType) || instanceType.startsWith('db.')) {
301301
this._instanceType = instanceType;
302302
} else {
303-
throw new Error(`instance type must start with 'db.'; (got ${instanceType})`);
303+
throw new cdk.UnscopedValidationError(`instance type must start with 'db.'; (got ${instanceType})`);
304304
}
305305
}
306306
}

0 commit comments

Comments
 (0)