Skip to content

Commit faee209

Browse files
authored
feat(cognito-identitypool): throw ValidationErrors instead of untyped Errors (#34109)
### Issue # (if applicable) Relates to #32569 ### Reason for this change Untyped Errors are not recommended. ### Description of changes Change Error to ValidationError / UnscopedValidationError ### 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 07f1d0a commit faee209

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const enableNoThrowDefaultErrorIn = [
4747
'aws-codepipeline',
4848
'aws-codepipeline-actions',
4949
'aws-cognito',
50+
'aws-cognito-identitypool',
5051
'aws-config',
5152
'aws-docdb',
5253
'aws-dynamodb',

packages/aws-cdk-lib/aws-cognito-identitypool/lib/identitypool.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Construct } from 'constructs';
22
import { IUserPoolAuthenticationProvider } from './identitypool-user-pool-authentication-provider';
33
import { CfnIdentityPool, CfnIdentityPoolRoleAttachment, IUserPool, IUserPoolClient } from '../../aws-cognito';
44
import { IOpenIdConnectProvider, ISamlProvider, Role, FederatedPrincipal, IRole } from '../../aws-iam';
5-
import { Resource, IResource, Stack, ArnFormat, Lazy, Token } from '../../core';
5+
import { Resource, IResource, Stack, ArnFormat, Lazy, Token, ValidationError, UnscopedValidationError } from '../../core';
66
import { addConstructMetadata, MethodMetadata } from '../../core/lib/metadata-resource';
77

88
/**
@@ -383,15 +383,15 @@ export class IdentityPool extends Resource implements IIdentityPool {
383383
const pool = Stack.of(scope).splitArn(identityPoolArn, ArnFormat.SLASH_RESOURCE_NAME);
384384
const res = pool.resourceName || '';
385385
if (!res) {
386-
throw new Error('Invalid Identity Pool ARN');
386+
throw new ValidationError('Invalid Identity Pool ARN', scope);
387387
}
388388
if (!Token.isUnresolved(res)) {
389389
const idParts = res.split(':');
390390
if (!(idParts.length === 2)) {
391-
throw new Error('Invalid Identity Pool Id: Identity Pool Ids must follow the format <region>:<id>');
391+
throw new ValidationError('Invalid Identity Pool Id: Identity Pool Ids must follow the format <region>:<id>', scope);
392392
}
393393
if (!Token.isUnresolved(pool.region) && idParts[0] !== pool.region) {
394-
throw new Error('Invalid Identity Pool Id: Region in Identity Pool Id must match stack region');
394+
throw new ValidationError('Invalid Identity Pool Id: Region in Identity Pool Id must match stack region', scope);
395395
}
396396
}
397397
class ImportedIdentityPool extends Resource implements IIdentityPool {
@@ -625,7 +625,7 @@ class IdentityPoolRoleAttachment extends Resource implements IIdentityPoolRoleAt
625625
} else {
626626
const providerUrl = prop.providerUrl.value;
627627
if (Token.isUnresolved(providerUrl)) {
628-
throw new Error('mappingKey must be provided when providerUrl.value is a token');
628+
throw new UnscopedValidationError('mappingKey must be provided when providerUrl.value is a token');
629629
}
630630
mappingKey = providerUrl;
631631
}
@@ -637,7 +637,7 @@ class IdentityPoolRoleAttachment extends Resource implements IIdentityPoolRoleAt
637637
};
638638
if (roleMapping.type === 'Rules') {
639639
if (!prop.rules) {
640-
throw new Error('IdentityPoolRoleMapping.rules is required when useToken is false');
640+
throw new UnscopedValidationError('IdentityPoolRoleMapping.rules is required when useToken is false');
641641
}
642642
roleMapping.rulesConfiguration = {
643643
rules: prop.rules.map(rule => {

0 commit comments

Comments
 (0)