From 11a75b287bbbc6067df52cf5946634877351d515 Mon Sep 17 00:00:00 2001 From: Kaizen Conroy <36202692+kaizencc@users.noreply.github.com> Date: Mon, 17 Feb 2025 11:08:02 -0500 Subject: [PATCH] feat(cloudtrail): throw `ValidationErrors` instead of untyped Errors (#33455) ### Issue Relates to #32569 ### Description of changes `ValidationErrors` everywhere ### 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* --- packages/aws-cdk-lib/.eslintrc.js | 1 + packages/aws-cdk-lib/aws-cloudtrail/lib/cloudtrail.ts | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk-lib/.eslintrc.js b/packages/aws-cdk-lib/.eslintrc.js index 83628120bab02..7b695c210cc0e 100644 --- a/packages/aws-cdk-lib/.eslintrc.js +++ b/packages/aws-cdk-lib/.eslintrc.js @@ -37,6 +37,7 @@ const enableNoThrowDefaultErrorIn = [ 'aws-cognito', 'aws-cloudfront', 'aws-cloudfront-origins', + 'aws-cloudtrail', 'aws-elasticloadbalancing', 'aws-elasticloadbalancingv2', 'aws-elasticloadbalancingv2-actions', diff --git a/packages/aws-cdk-lib/aws-cloudtrail/lib/cloudtrail.ts b/packages/aws-cdk-lib/aws-cloudtrail/lib/cloudtrail.ts index 19994f4e4a294..5bae5a7bc1087 100644 --- a/packages/aws-cdk-lib/aws-cloudtrail/lib/cloudtrail.ts +++ b/packages/aws-cdk-lib/aws-cloudtrail/lib/cloudtrail.ts @@ -7,7 +7,7 @@ import * as lambda from '../../aws-lambda'; import * as logs from '../../aws-logs'; import * as s3 from '../../aws-s3'; import * as sns from '../../aws-sns'; -import { Resource, Stack } from '../../core'; +import { Resource, Stack, ValidationError } from '../../core'; import { addConstructMetadata, MethodMetadata } from '../../core/lib/metadata-resource'; /** @@ -322,7 +322,7 @@ export class Trail extends Resource { this.node.addValidation({ validate: () => this.validateEventSelectors() }); if (props.kmsKey && props.encryptionKey) { - throw new Error('Both kmsKey and encryptionKey must not be specified. Use only encryptionKey'); + throw new ValidationError('Both kmsKey and encryptionKey must not be specified. Use only encryptionKey', this); } if (props.insightTypes) { @@ -384,11 +384,11 @@ export class Trail extends Resource { @MethodMetadata() public addEventSelector(dataResourceType: DataResourceType, dataResourceValues: string[], options: AddEventSelectorOptions = {}) { if (dataResourceValues.length > 250) { - throw new Error('A maximum of 250 data elements can be in one event selector'); + throw new ValidationError('A maximum of 250 data elements can be in one event selector', this); } if (this.eventSelectors.length > 5) { - throw new Error('A maximum of 5 event selectors are supported per trail.'); + throw new ValidationError('A maximum of 5 event selectors are supported per trail.', this); } let includeAllManagementEvents;