Skip to content

Commit 11a75b2

Browse files
authored
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*
1 parent 67e596e commit 11a75b2

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

packages/aws-cdk-lib/.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const enableNoThrowDefaultErrorIn = [
3737
'aws-cognito',
3838
'aws-cloudfront',
3939
'aws-cloudfront-origins',
40+
'aws-cloudtrail',
4041
'aws-elasticloadbalancing',
4142
'aws-elasticloadbalancingv2',
4243
'aws-elasticloadbalancingv2-actions',

packages/aws-cdk-lib/aws-cloudtrail/lib/cloudtrail.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as lambda from '../../aws-lambda';
77
import * as logs from '../../aws-logs';
88
import * as s3 from '../../aws-s3';
99
import * as sns from '../../aws-sns';
10-
import { Resource, Stack } from '../../core';
10+
import { Resource, Stack, ValidationError } from '../../core';
1111
import { addConstructMetadata, MethodMetadata } from '../../core/lib/metadata-resource';
1212

1313
/**
@@ -322,7 +322,7 @@ export class Trail extends Resource {
322322
this.node.addValidation({ validate: () => this.validateEventSelectors() });
323323

324324
if (props.kmsKey && props.encryptionKey) {
325-
throw new Error('Both kmsKey and encryptionKey must not be specified. Use only encryptionKey');
325+
throw new ValidationError('Both kmsKey and encryptionKey must not be specified. Use only encryptionKey', this);
326326
}
327327

328328
if (props.insightTypes) {
@@ -384,11 +384,11 @@ export class Trail extends Resource {
384384
@MethodMetadata()
385385
public addEventSelector(dataResourceType: DataResourceType, dataResourceValues: string[], options: AddEventSelectorOptions = {}) {
386386
if (dataResourceValues.length > 250) {
387-
throw new Error('A maximum of 250 data elements can be in one event selector');
387+
throw new ValidationError('A maximum of 250 data elements can be in one event selector', this);
388388
}
389389

390390
if (this.eventSelectors.length > 5) {
391-
throw new Error('A maximum of 5 event selectors are supported per trail.');
391+
throw new ValidationError('A maximum of 5 event selectors are supported per trail.', this);
392392
}
393393

394394
let includeAllManagementEvents;

0 commit comments

Comments
 (0)