From c635bef2365f6da79a2f777acccec3727b649ee5 Mon Sep 17 00:00:00 2001 From: CarlosGamero Date: Thu, 24 Apr 2025 16:59:56 +0200 Subject: [PATCH 1/5] Improving topic creation error --- packages/sns/lib/utils/snsUtils.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/sns/lib/utils/snsUtils.ts b/packages/sns/lib/utils/snsUtils.ts index 974b653a..823e7101 100644 --- a/packages/sns/lib/utils/snsUtils.ts +++ b/packages/sns/lib/utils/snsUtils.ts @@ -96,7 +96,14 @@ export async function assertTopic( } catch (error) { if (!isError(error)) throw error // To build ARN we need topic name and error should be "topic already exist with different tags" - if (!topicOptions.Name || !isTopicAlreadyExistWithDifferentTagsError(error)) throw error + if (!topicOptions.Name || !isTopicAlreadyExistWithDifferentTagsError(error)) { + throw new InternalError({ + message: error.message, + cause: error, + details: { topicName: topicOptions.Name }, + errorCode: 'SNS_CREATE_TOPIC_COMMAND_UNEXPECTED_ERROR', + }) + } topicArn = await buildTopicArn(stsClient, topicOptions.Name) if (!extraParams?.forceTagUpdate) { @@ -104,8 +111,9 @@ export async function assertTopic( new ListTagsForResourceCommand({ ResourceArn: topicArn }), ) throw new InternalError({ - message: `${topicOptions.Name} - ${error.message}`, + message: error.message, details: { + topicName: topicOptions.Name, currentTags: JSON.stringify(currentTags), newTags: JSON.stringify(topicOptions.Tags), }, From efff22a8d056458c253ba3821916fef71e13ea65 Mon Sep 17 00:00:00 2001 From: CarlosGamero Date: Thu, 24 Apr 2025 17:00:16 +0200 Subject: [PATCH 2/5] Release prepare --- packages/sns/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sns/package.json b/packages/sns/package.json index 458336a7..792e49c1 100644 --- a/packages/sns/package.json +++ b/packages/sns/package.json @@ -1,6 +1,6 @@ { "name": "@message-queue-toolkit/sns", - "version": "21.1.1", + "version": "21.1.2", "private": false, "license": "MIT", "description": "SNS adapter for message-queue-toolkit", From f007e50724073d588fa151556afc1f3fb49ab9c3 Mon Sep 17 00:00:00 2001 From: CarlosGamero Date: Thu, 24 Apr 2025 17:09:36 +0200 Subject: [PATCH 3/5] Fixing tests --- packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts | 2 +- packages/sns/test/publishers/SnsPermissionPublisher.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts b/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts index 8e81ad5c..390e5ba9 100644 --- a/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts +++ b/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts @@ -297,7 +297,7 @@ describe('SnsSqsPermissionConsumer', () => { }) await expect(consumer.init()).rejects.toThrowError( - `${topicNome} - Invalid parameter: Tags Reason: Topic already exists with different tags`, + 'Invalid parameter: Tags Reason: Topic already exists with different tags', ) }) diff --git a/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts b/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts index af9925b0..f1c7dccf 100644 --- a/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts +++ b/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts @@ -171,7 +171,7 @@ describe('SnsPermissionPublisher', () => { }) await expect(newPublisher.init()).rejects.toThrowError( - `${topicNome} - Invalid parameter: Tags Reason: Topic already exists with different tags`, + 'Invalid parameter: Tags Reason: Topic already exists with different tags', ) }) }) From 00f8df685bda043e4442e1f629e413a3edb8e818 Mon Sep 17 00:00:00 2001 From: CarlosGamero Date: Thu, 24 Apr 2025 17:12:17 +0200 Subject: [PATCH 4/5] Revert "Fixing tests" This reverts commit f007e50724073d588fa151556afc1f3fb49ab9c3. --- packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts | 2 +- packages/sns/test/publishers/SnsPermissionPublisher.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts b/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts index 390e5ba9..8e81ad5c 100644 --- a/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts +++ b/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts @@ -297,7 +297,7 @@ describe('SnsSqsPermissionConsumer', () => { }) await expect(consumer.init()).rejects.toThrowError( - 'Invalid parameter: Tags Reason: Topic already exists with different tags', + `${topicNome} - Invalid parameter: Tags Reason: Topic already exists with different tags`, ) }) diff --git a/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts b/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts index f1c7dccf..af9925b0 100644 --- a/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts +++ b/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts @@ -171,7 +171,7 @@ describe('SnsPermissionPublisher', () => { }) await expect(newPublisher.init()).rejects.toThrowError( - 'Invalid parameter: Tags Reason: Topic already exists with different tags', + `${topicNome} - Invalid parameter: Tags Reason: Topic already exists with different tags`, ) }) }) From 4e85441fdfeb8ffe5c5da165e86111c3baad76e1 Mon Sep 17 00:00:00 2001 From: CarlosGamero Date: Thu, 24 Apr 2025 17:14:02 +0200 Subject: [PATCH 5/5] Improving error message --- packages/sns/lib/utils/snsUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sns/lib/utils/snsUtils.ts b/packages/sns/lib/utils/snsUtils.ts index 823e7101..4ca381b8 100644 --- a/packages/sns/lib/utils/snsUtils.ts +++ b/packages/sns/lib/utils/snsUtils.ts @@ -98,7 +98,7 @@ export async function assertTopic( // To build ARN we need topic name and error should be "topic already exist with different tags" if (!topicOptions.Name || !isTopicAlreadyExistWithDifferentTagsError(error)) { throw new InternalError({ - message: error.message, + message: `${topicOptions.Name} - ${error.message}`, cause: error, details: { topicName: topicOptions.Name }, errorCode: 'SNS_CREATE_TOPIC_COMMAND_UNEXPECTED_ERROR', @@ -111,7 +111,7 @@ export async function assertTopic( new ListTagsForResourceCommand({ ResourceArn: topicArn }), ) throw new InternalError({ - message: error.message, + message: `${topicOptions.Name} - ${error.message}`, details: { topicName: topicOptions.Name, currentTags: JSON.stringify(currentTags),