Skip to content

Commit b4efb1e

Browse files
authored
feat(appconfig): throw ValidationError instead of untyped Errors (#33386)
### 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 14b1098 commit b4efb1e

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const enableNoThrowDefaultErrorIn = [
2323
'aws-apigatewayv2',
2424
'aws-apigatewayv2-authorizers',
2525
'aws-apigatewayv2-integrations',
26+
'aws-appconfig',
2627
'aws-applicationautoscaling',
2728
'aws-appsync',
2829
'aws-appmesh',

packages/aws-cdk-lib/aws-appconfig/lib/application.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ export class Application extends ApplicationBase {
346346
const parsedArn = cdk.Stack.of(scope).splitArn(applicationArn, cdk.ArnFormat.SLASH_RESOURCE_NAME);
347347
const applicationId = parsedArn.resourceName;
348348
if (!applicationId) {
349-
throw new Error('Missing required application id from application ARN');
349+
throw new cdk.ValidationError('Missing required application id from application ARN', scope);
350350
}
351351

352352
class Import extends ApplicationBase {

packages/aws-cdk-lib/aws-appconfig/lib/deployment-strategy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Construct } from 'constructs';
22
import { CfnDeploymentStrategy } from './appconfig.generated';
3-
import { Resource, IResource, Stack, ArnFormat, Names, Duration } from '../../core';
3+
import { Resource, IResource, Stack, ArnFormat, Names, Duration, ValidationError } from '../../core';
44
import { addConstructMetadata } from '../../core/lib/metadata-resource';
55

66
/**
@@ -47,7 +47,7 @@ export class DeploymentStrategy extends Resource implements IDeploymentStrategy
4747
const parsedArn = Stack.of(scope).splitArn(deploymentStrategyArn, ArnFormat.SLASH_RESOURCE_NAME);
4848
const deploymentStrategyId = parsedArn.resourceName;
4949
if (!deploymentStrategyId) {
50-
throw new Error('Missing required deployment strategy id from deployment strategy ARN');
50+
throw new ValidationError('Missing required deployment strategy id from deployment strategy ARN', scope);
5151
}
5252

5353
class Import extends Resource implements IDeploymentStrategy {

packages/aws-cdk-lib/aws-appconfig/lib/environment.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getHash } from './private/hash';
77
import { DeletionProtectionCheck } from './util';
88
import * as cloudwatch from '../../aws-cloudwatch';
99
import * as iam from '../../aws-iam';
10-
import { Resource, IResource, Stack, ArnFormat, PhysicalName, Names } from '../../core';
10+
import { Resource, IResource, Stack, ArnFormat, PhysicalName, Names, ValidationError, UnscopedValidationError } from '../../core';
1111
import { addConstructMetadata } from '../../core/lib/metadata-resource';
1212

1313
/**
@@ -56,7 +56,7 @@ abstract class EnvironmentBase extends Resource implements IEnvironment, IExtens
5656

5757
public addDeployment(configuration: IConfiguration): void {
5858
if (this.name === undefined) {
59-
throw new Error('Environment name must be known to add a Deployment');
59+
throw new ValidationError('Environment name must be known to add a Deployment', this);
6060
}
6161

6262
const queueSize = this.deploymentQueue.push(
@@ -203,12 +203,12 @@ export class Environment extends EnvironmentBase {
203203
public static fromEnvironmentArn(scope: Construct, id: string, environmentArn: string): IEnvironment {
204204
const parsedArn = Stack.of(scope).splitArn(environmentArn, ArnFormat.SLASH_RESOURCE_NAME);
205205
if (!parsedArn.resourceName) {
206-
throw new Error(`Missing required /$/{applicationId}/environment//$/{environmentId} from environment ARN: ${parsedArn.resourceName}`);
206+
throw new ValidationError(`Missing required /$/{applicationId}/environment//$/{environmentId} from environment ARN: ${parsedArn.resourceName}`, scope);
207207
}
208208

209209
const resourceName = parsedArn.resourceName.split('/');
210210
if (resourceName.length != 3 || !resourceName[0] || !resourceName[2]) {
211-
throw new Error('Missing required parameters for environment ARN: format should be /$/{applicationId}/environment//$/{environmentId}');
211+
throw new ValidationError('Missing required parameters for environment ARN: format should be /$/{applicationId}/environment//$/{environmentId}', scope);
212212
}
213213

214214
const applicationId = resourceName[0];
@@ -413,7 +413,7 @@ export abstract class Monitor {
413413
*/
414414
public static fromCfnMonitorsProperty(monitorsProperty: CfnEnvironment.MonitorsProperty): Monitor {
415415
if (monitorsProperty.alarmArn === undefined) {
416-
throw new Error('You must specify an alarmArn property to use "fromCfnMonitorsProperty".');
416+
throw new UnscopedValidationError('You must specify an alarmArn property to use "fromCfnMonitorsProperty".');
417417
}
418418
return {
419419
alarmArn: monitorsProperty.alarmArn,

packages/aws-cdk-lib/aws-appconfig/lib/extension.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as iam from '../../aws-iam';
66
import * as lambda from '../../aws-lambda';
77
import * as sns from '../../aws-sns';
88
import * as sqs from '../../aws-sqs';
9-
import { ArnFormat, IResource, Names, PhysicalName, Resource, Stack } from '../../core';
9+
import { ArnFormat, IResource, Names, PhysicalName, Resource, Stack, ValidationError } from '../../core';
1010
import { addConstructMetadata } from '../../core/lib/metadata-resource';
1111

1212
/**
@@ -393,12 +393,12 @@ export class Extension extends Resource implements IExtension {
393393
public static fromExtensionArn(scope: Construct, id: string, extensionArn: string): IExtension {
394394
const parsedArn = Stack.of(scope).splitArn(extensionArn, ArnFormat.SLASH_RESOURCE_NAME);
395395
if (!parsedArn.resourceName) {
396-
throw new Error(`Missing required /$/{extensionId}//$/{extensionVersionNumber} from configuration profile ARN: ${parsedArn.resourceName}`);
396+
throw new ValidationError(`Missing required /$/{extensionId}//$/{extensionVersionNumber} from configuration profile ARN: ${parsedArn.resourceName}`, scope);
397397
}
398398

399399
const resourceName = parsedArn.resourceName.split('/');
400400
if (resourceName.length != 2 || !resourceName[0] || !resourceName[1]) {
401-
throw new Error('Missing required parameters for extension ARN: format should be /$/{extensionId}//$/{extensionVersionNumber}');
401+
throw new ValidationError('Missing required parameters for extension ARN: format should be /$/{extensionId}//$/{extensionVersionNumber}', scope);
402402
}
403403

404404
const extensionId = resourceName[0];

0 commit comments

Comments
 (0)