Skip to content

Commit 4ae78b0

Browse files
authored
fix(cognito): ambiguous error message when same trigger is added twice (aws#16917)
when the same trigger is added twice to the Cognito userpool, ```ts const fn = lambda.Function.fromFunctionArn(stack, 'Trigger', 'arn:aws:lambda:us-east-1:123456789012:function:CognitoFunction') const userpool = new cognito.UserPool(stack, 'Userpool', { lambdaTriggers: { customMessage: fn } }) userpool.addTrigger(cognito.UserPoolOperation.CUSTOM_MESSAGE, fn) ``` throws error message: `Error: A trigger for the operation [object Object] already exists.` This PR fixes it as: ` Error: A trigger for the operation customMessage already exists.` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 1aa1588 commit 4ae78b0

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

packages/@aws-cdk/aws-cognito/lib/user-pool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ export class UserPool extends UserPoolBase {
830830
*/
831831
public addTrigger(operation: UserPoolOperation, fn: lambda.IFunction): void {
832832
if (operation.operationName in this.triggers) {
833-
throw new Error(`A trigger for the operation ${operation} already exists.`);
833+
throw new Error(`A trigger for the operation ${operation.operationName} already exists.`);
834834
}
835835

836836
this.addLambdaPermission(fn, operation.operationName);

packages/@aws-cdk/aws-cognito/test/user-pool.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ describe('User Pool', () => {
403403

404404
// WHEN
405405
userpool.addTrigger(UserPoolOperation.CREATE_AUTH_CHALLENGE, fn1);
406-
expect(() => userpool.addTrigger(UserPoolOperation.CREATE_AUTH_CHALLENGE, fn2)).toThrow(/already exists/);
406+
expect(() => userpool.addTrigger(UserPoolOperation.CREATE_AUTH_CHALLENGE, fn2)).toThrow(/createAuthChallenge already exists/);
407407
});
408408

409409
test('no username aliases specified', () => {

0 commit comments

Comments
 (0)