Skip to content

Commit

Permalink
feat(cloudtrail): throw ValidationErrors instead of untyped Errors (#…
Browse files Browse the repository at this point in the history
…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*
  • Loading branch information
kaizencc authored Feb 17, 2025
1 parent 67e596e commit 11a75b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const enableNoThrowDefaultErrorIn = [
'aws-cognito',
'aws-cloudfront',
'aws-cloudfront-origins',
'aws-cloudtrail',
'aws-elasticloadbalancing',
'aws-elasticloadbalancingv2',
'aws-elasticloadbalancingv2-actions',
Expand Down
8 changes: 4 additions & 4 deletions packages/aws-cdk-lib/aws-cloudtrail/lib/cloudtrail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 11a75b2

Please sign in to comment.