Skip to content

Commit 8b23b5d

Browse files
authored
feat(kinesisfirehose): throw ValidationErrors instead of untyped Errors (#33912)
### Issue # (if applicable) `aws-kinesisfirehose` for #32569 ### Description of changes ValidationErrors everywhere ### Describe any new or updated permissions being added None ### 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 5fff3d6 commit 8b23b5d

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

Diff for: packages/aws-cdk-lib/.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const enableNoThrowDefaultErrorIn = [
5757
'aws-elasticloadbalancingv2',
5858
'aws-elasticloadbalancingv2-actions',
5959
'aws-elasticloadbalancingv2-targets',
60+
'aws-kinesisfirehose',
6061
'aws-lambda',
6162
'aws-logs',
6263
'aws-rds',

Diff for: packages/aws-cdk-lib/aws-kinesisfirehose/lib/delivery-stream.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,13 @@ export class DeliveryStream extends DeliveryStreamBase {
277277
*/
278278
static fromDeliveryStreamAttributes(scope: Construct, id: string, attrs: DeliveryStreamAttributes): IDeliveryStream {
279279
if (!attrs.deliveryStreamName && !attrs.deliveryStreamArn) {
280-
throw new Error('Either deliveryStreamName or deliveryStreamArn must be provided in DeliveryStreamAttributes');
280+
throw new cdk.ValidationError('Either deliveryStreamName or deliveryStreamArn must be provided in DeliveryStreamAttributes', scope);
281281
}
282282
const deliveryStreamName = attrs.deliveryStreamName ??
283283
cdk.Stack.of(scope).splitArn(attrs.deliveryStreamArn!, cdk.ArnFormat.SLASH_RESOURCE_NAME).resourceName;
284284

285285
if (!deliveryStreamName) {
286-
throw new Error(`No delivery stream name found in ARN: '${attrs.deliveryStreamArn}'`);
286+
throw new cdk.ValidationError(`No delivery stream name found in ARN: '${attrs.deliveryStreamArn}'`, scope);
287287
}
288288
const deliveryStreamArn = attrs.deliveryStreamArn ?? cdk.Stack.of(scope).formatArn({
289289
service: 'firehose',
@@ -334,7 +334,7 @@ export class DeliveryStream extends DeliveryStreamBase {
334334
props.source &&
335335
(props.encryption?.type === StreamEncryptionType.AWS_OWNED || props.encryption?.type === StreamEncryptionType.CUSTOMER_MANAGED)
336336
) {
337-
throw new Error('Requested server-side encryption but delivery stream source is a Kinesis data stream. Specify server-side encryption on the data stream instead.');
337+
throw new cdk.ValidationError('Requested server-side encryption but delivery stream source is a Kinesis data stream. Specify server-side encryption on the data stream instead.', this);
338338
}
339339
const encryptionKey = props.encryption?.encryptionKey ?? (props.encryption?.type === StreamEncryptionType.CUSTOMER_MANAGED ? new kms.Key(this, 'Key') : undefined);
340340
const encryptionConfig = (encryptionKey || (props.encryption?.type === StreamEncryptionType.AWS_OWNED)) ? {

Diff for: packages/aws-cdk-lib/aws-kinesisfirehose/lib/private/helpers.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export function createLoggingOptions(scope: Construct, props: DestinationLogging
6969
}
7070

7171
export function createBufferingHints(
72+
scope: Construct,
7273
interval?: cdk.Duration,
7374
size?: cdk.Size,
7475
): CfnDeliveryStream.BufferingHintsProperty | undefined {
@@ -78,11 +79,11 @@ export function createBufferingHints(
7879

7980
const intervalInSeconds = interval?.toSeconds() ?? 300;
8081
if (intervalInSeconds > 900) {
81-
throw new Error(`Buffering interval must be less than 900 seconds. Buffering interval provided was ${intervalInSeconds} seconds.`);
82+
throw new cdk.ValidationError(`Buffering interval must be less than 900 seconds. Buffering interval provided was ${intervalInSeconds} seconds.`, scope);
8283
}
8384
const sizeInMBs = size?.toMebibytes() ?? 5;
8485
if (sizeInMBs < 1 || sizeInMBs > 128) {
85-
throw new Error(`Buffering size must be between 1 and 128 MiBs. Buffering size provided was ${sizeInMBs} MiBs.`);
86+
throw new cdk.ValidationError(`Buffering size must be between 1 and 128 MiBs. Buffering size provided was ${sizeInMBs} MiBs.`, scope);
8687
}
8788
return { intervalInSeconds, sizeInMBs };
8889
}
@@ -153,7 +154,7 @@ export function createBackupConfig(scope: Construct, role: iam.IRole, props?: De
153154
roleArn: role.roleArn,
154155
prefix: props.dataOutputPrefix,
155156
errorOutputPrefix: props.errorOutputPrefix,
156-
bufferingHints: createBufferingHints(props.bufferingInterval, props.bufferingSize),
157+
bufferingHints: createBufferingHints(scope, props.bufferingInterval, props.bufferingSize),
157158
compressionFormat: props.compression?.value,
158159
encryptionConfiguration: createEncryptionConfig(role, props.encryptionKey),
159160
cloudWatchLoggingOptions: loggingOptions,

Diff for: packages/aws-cdk-lib/aws-kinesisfirehose/lib/s3-bucket.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { DestinationBindOptions, DestinationConfig, IDestination } from './desti
44
import * as iam from '../../aws-iam';
55
import * as s3 from '../../aws-s3';
66
import { createBackupConfig, createBufferingHints, createEncryptionConfig, createLoggingOptions, createProcessingConfig } from './private/helpers';
7+
import { UnscopedValidationError } from '../../core';
78

89
/**
910
* Props for defining an S3 destination of an Amazon Data Firehose delivery stream.
@@ -17,7 +18,7 @@ export interface S3BucketProps extends CommonDestinationS3Props, CommonDestinati
1718
export class S3Bucket implements IDestination {
1819
constructor(private readonly bucket: s3.IBucket, private readonly props: S3BucketProps = {}) {
1920
if (this.props.s3Backup?.mode === BackupMode.FAILED) {
20-
throw new Error('S3 destinations do not support BackupMode.FAILED');
21+
throw new UnscopedValidationError('S3 destinations do not support BackupMode.FAILED');
2122
}
2223
}
2324

@@ -42,7 +43,7 @@ export class S3Bucket implements IDestination {
4243
roleArn: role.roleArn,
4344
s3BackupConfiguration: backupConfig,
4445
s3BackupMode: this.getS3BackupMode(),
45-
bufferingHints: createBufferingHints(this.props.bufferingInterval, this.props.bufferingSize),
46+
bufferingHints: createBufferingHints(scope, this.props.bufferingInterval, this.props.bufferingSize),
4647
bucketArn: this.bucket.bucketArn,
4748
compressionFormat: this.props.compression?.value,
4849
encryptionConfiguration: createEncryptionConfig(role, this.props.encryptionKey),

0 commit comments

Comments
 (0)