From ee80e720c9e527ad632cf539f03576b7ca509901 Mon Sep 17 00:00:00 2001 From: tttol Date: Thu, 10 Apr 2025 14:20:21 +0900 Subject: [PATCH] change Error to ValidationError/UnscopedValidationError --- packages/aws-cdk-lib/.eslintrc.js | 1 + packages/aws-cdk-lib/aws-ses-actions/lib/add-header.ts | 5 +++-- .../aws-ses/lib/configuration-set-event-destination.ts | 4 ++-- packages/aws-cdk-lib/aws-ses/lib/configuration-set.ts | 8 ++++---- packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/aws-cdk-lib/.eslintrc.js b/packages/aws-cdk-lib/.eslintrc.js index 3efbc50ada32f..6322f25301d61 100644 --- a/packages/aws-cdk-lib/.eslintrc.js +++ b/packages/aws-cdk-lib/.eslintrc.js @@ -62,6 +62,7 @@ const enableNoThrowDefaultErrorIn = [ 'aws-logs', 'aws-rds', 'aws-s3', + 'aws-ses', 'aws-sns', 'aws-sqs', 'aws-ssm', diff --git a/packages/aws-cdk-lib/aws-ses-actions/lib/add-header.ts b/packages/aws-cdk-lib/aws-ses-actions/lib/add-header.ts index 4c9a667f55dd3..491ab4dfd700e 100644 --- a/packages/aws-cdk-lib/aws-ses-actions/lib/add-header.ts +++ b/packages/aws-cdk-lib/aws-ses-actions/lib/add-header.ts @@ -1,4 +1,5 @@ import * as ses from '../../aws-ses'; +import { UnscopedValidationError } from '../../core'; /** * Construction properties for a add header action. @@ -28,11 +29,11 @@ export class AddHeader implements ses.IReceiptRuleAction { constructor(props: AddHeaderProps) { if (!/^[a-zA-Z0-9-]{1,50}$/.test(props.name)) { // eslint-disable-next-line max-len - throw new Error('Header `name` must be between 1 and 50 characters, inclusive, and consist of alphanumeric (a-z, A-Z, 0-9) characters and dashes only.'); + throw new UnscopedValidationError('Header `name` must be between 1 and 50 characters, inclusive, and consist of alphanumeric (a-z, A-Z, 0-9) characters and dashes only.'); } if (!/^[^\n\r]{0,2047}$/.test(props.value)) { - throw new Error('Header `value` must be less than 2048 characters, and must not contain newline characters ("\r" or "\n").'); + throw new UnscopedValidationError('Header `value` must be less than 2048 characters, and must not contain newline characters ("\r" or "\n").'); } this.name = props.name; diff --git a/packages/aws-cdk-lib/aws-ses/lib/configuration-set-event-destination.ts b/packages/aws-cdk-lib/aws-ses/lib/configuration-set-event-destination.ts index e9c06fcd79f95..b21f305a1d04b 100644 --- a/packages/aws-cdk-lib/aws-ses/lib/configuration-set-event-destination.ts +++ b/packages/aws-cdk-lib/aws-ses/lib/configuration-set-event-destination.ts @@ -5,7 +5,7 @@ import * as events from '../../aws-events'; import * as iam from '../../aws-iam'; import * as firehose from '../../aws-kinesisfirehose'; import * as sns from '../../aws-sns'; -import { Aws, IResource, Resource, Stack } from '../../core'; +import { Aws, IResource, Resource, Stack, ValidationError } from '../../core'; import { addConstructMetadata } from '../../core/lib/metadata-resource'; /** @@ -296,7 +296,7 @@ export class ConfigurationSetEventDestination extends Resource implements IConfi resourceName: 'default', }) ) { - throw new Error(`Only the default bus can be used as an event destination. Got ${props.destination.bus.eventBusArn}`); + throw new ValidationError(`Only the default bus can be used as an event destination. Got ${props.destination.bus.eventBusArn}`, this); } let firehoseDeliveryStreamIamRoleArn = ''; diff --git a/packages/aws-cdk-lib/aws-ses/lib/configuration-set.ts b/packages/aws-cdk-lib/aws-ses/lib/configuration-set.ts index df4ea2f020e12..6dc9fb002a270 100644 --- a/packages/aws-cdk-lib/aws-ses/lib/configuration-set.ts +++ b/packages/aws-cdk-lib/aws-ses/lib/configuration-set.ts @@ -3,7 +3,7 @@ import { ConfigurationSetEventDestination, ConfigurationSetEventDestinationOptio import { IDedicatedIpPool } from './dedicated-ip-pool'; import { undefinedIfNoKeys } from './private/utils'; import { CfnConfigurationSet } from './ses.generated'; -import { Duration, IResource, Resource, Token } from '../../core'; +import { Duration, IResource, Resource, Token, ValidationError } from '../../core'; import { addConstructMetadata, MethodMetadata } from '../../core/lib/metadata-resource'; /** @@ -179,14 +179,14 @@ export class ConfigurationSet extends Resource implements IConfigurationSet { addConstructMetadata(this, props); if (props.disableSuppressionList && props.suppressionReasons) { - throw new Error('When disableSuppressionList is true, suppressionReasons must not be specified.'); + throw new ValidationError('When disableSuppressionList is true, suppressionReasons must not be specified.', this); } if (props.maxDeliveryDuration && !Token.isUnresolved(props.maxDeliveryDuration)) { if (props.maxDeliveryDuration.toMilliseconds() < Duration.minutes(5).toMilliseconds()) { - throw new Error(`The maximum delivery duration must be greater than or equal to 5 minutes (300_000 milliseconds), got: ${props.maxDeliveryDuration.toMilliseconds()} milliseconds.`); + throw new ValidationError(`The maximum delivery duration must be greater than or equal to 5 minutes (300_000 milliseconds), got: ${props.maxDeliveryDuration.toMilliseconds()} milliseconds.`, this); } if (props.maxDeliveryDuration.toSeconds() > Duration.hours(14).toSeconds()) { - throw new Error(`The maximum delivery duration must be less than or equal to 14 hours (50400 seconds), got: ${props.maxDeliveryDuration.toSeconds()} seconds.`); + throw new ValidationError(`The maximum delivery duration must be less than or equal to 14 hours (50400 seconds), got: ${props.maxDeliveryDuration.toSeconds()} seconds.`, this); } } diff --git a/packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts b/packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts index d35fb856138df..0d467b925e111 100644 --- a/packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts +++ b/packages/aws-cdk-lib/aws-ses/lib/dedicated-ip-pool.ts @@ -1,6 +1,6 @@ import { Construct } from 'constructs'; import { CfnDedicatedIpPool } from './ses.generated'; -import { IResource, Resource } from '../../core'; +import { IResource, Resource, ValidationError } from '../../core'; import { addConstructMetadata } from '../../core/lib/metadata-resource'; /** @@ -82,7 +82,7 @@ export class DedicatedIpPool extends Resource implements IDedicatedIpPool { addConstructMetadata(this, props); if (props.dedicatedIpPoolName && !/^[a-z0-9_-]{0,64}$/.test(props.dedicatedIpPoolName)) { - throw new Error(`Invalid dedicatedIpPoolName "${props.dedicatedIpPoolName}". The name must only include lowercase letters, numbers, underscores, hyphens, and must not exceed 64 characters.`); + throw new ValidationError(`Invalid dedicatedIpPoolName "${props.dedicatedIpPoolName}". The name must only include lowercase letters, numbers, underscores, hyphens, and must not exceed 64 characters.`, this); } const pool = new CfnDedicatedIpPool(this, 'Resource', {