|
1 | 1 | import * as iam from 'aws-cdk-lib/aws-iam'; |
2 | 2 | import * as kms from 'aws-cdk-lib/aws-kms'; |
3 | | -import { ArnFormat, IResource, Lazy, Resource, Stack, Token } from 'aws-cdk-lib/core'; |
| 3 | +import { ArnFormat, IResource, Lazy, Resource, Stack, Token, UnscopedValidationError, ValidationError } from 'aws-cdk-lib/core'; |
4 | 4 | import { Construct } from 'constructs'; |
5 | 5 | import { CfnGeofenceCollection } from 'aws-cdk-lib/aws-location'; |
6 | 6 | import { generateUniqueId } from './util'; |
@@ -81,7 +81,7 @@ export class GeofenceCollection extends Resource implements IGeofenceCollection |
81 | 81 | const parsedArn = Stack.of(scope).splitArn(geofenceCollectionArn, ArnFormat.SLASH_RESOURCE_NAME); |
82 | 82 |
|
83 | 83 | if (!parsedArn.resourceName) { |
84 | | - throw new Error(`Geofence Collection Arn ${geofenceCollectionArn} does not have a resource name.`); |
| 84 | + throw new UnscopedValidationError(`Geofence Collection Arn ${geofenceCollectionArn} does not have a resource name.`); |
85 | 85 | } |
86 | 86 |
|
87 | 87 | class Import extends Resource implements IGeofenceCollection { |
@@ -114,26 +114,25 @@ export class GeofenceCollection extends Resource implements IGeofenceCollection |
114 | 114 | public readonly geofenceCollectionUpdateTime: string; |
115 | 115 |
|
116 | 116 | constructor(scope: Construct, id: string, props: GeofenceCollectionProps = {}) { |
| 117 | + super(scope, id, { |
| 118 | + physicalName: props.geofenceCollectionName ?? Lazy.string({ produce: () => generateUniqueId(this) }), |
| 119 | + }); |
| 120 | + // Enhanced CDK Analytics Telemetry |
| 121 | + addConstructMetadata(this, props); |
| 122 | + |
117 | 123 | if (props.description && !Token.isUnresolved(props.description) && props.description.length > 1000) { |
118 | | - throw new Error(`\`description\` must be between 0 and 1000 characters. Received: ${props.description.length} characters`); |
| 124 | + throw new ValidationError(`\`description\` must be between 0 and 1000 characters. Received: ${props.description.length} characters`, this); |
119 | 125 | } |
120 | 126 |
|
121 | 127 | if (props.geofenceCollectionName !== undefined && !Token.isUnresolved(props.geofenceCollectionName)) { |
122 | 128 | if (props.geofenceCollectionName.length < 1 || props.geofenceCollectionName.length > 100) { |
123 | | - throw new Error(`\`geofenceCollectionName\` must be between 1 and 100 characters, got: ${props.geofenceCollectionName.length} characters.`); |
| 129 | + throw new ValidationError(`\`geofenceCollectionName\` must be between 1 and 100 characters, got: ${props.geofenceCollectionName.length} characters.`, this); |
124 | 130 | } |
125 | 131 |
|
126 | 132 | if (!/^[-._\w]+$/.test(props.geofenceCollectionName)) { |
127 | | - throw new Error(`\`geofenceCollectionName\` must contain only alphanumeric characters, hyphens, periods and underscores, got: ${props.geofenceCollectionName}.`); |
| 133 | + throw new ValidationError(`\`geofenceCollectionName\` must contain only alphanumeric characters, hyphens, periods and underscores, got: ${props.geofenceCollectionName}.`, this); |
128 | 134 | } |
129 | 135 | } |
130 | | - |
131 | | - super(scope, id, { |
132 | | - physicalName: props.geofenceCollectionName ?? Lazy.string({ produce: () => generateUniqueId(this) }), |
133 | | - }); |
134 | | - // Enhanced CDK Analytics Telemetry |
135 | | - addConstructMetadata(this, props); |
136 | | - |
137 | 136 | const geofenceCollection = new CfnGeofenceCollection(this, 'Resource', { |
138 | 137 | collectionName: this.physicalName, |
139 | 138 | description: props.description, |
|
0 commit comments