From 4696f384d6716bcb9e4910e6d540588361c95229 Mon Sep 17 00:00:00 2001 From: rddimon Date: Thu, 7 Mar 2024 17:45:36 +0200 Subject: [PATCH 1/3] Fix Cloudformation error message --- CHANGELOG.md | 5 +++++ package.json | 2 +- src/aws/cloud-formation-wrapper.ts | 6 +++++- test/unit-tests/aws/cloud-formation-wrapper.test.ts | 8 ++++---- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index caa97ca4..07327188 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [7.3.8] - 2023-03-07 + +### Fixed +- Updated Cloudformation find API id error message + ## [7.3.7] - 2023-03-06 ### Fixed diff --git a/package.json b/package.json index 61caffdf..4aa8b4fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-domain-manager", - "version": "7.3.7", + "version": "7.3.8", "engines": { "node": ">=14" }, diff --git a/src/aws/cloud-formation-wrapper.ts b/src/aws/cloud-formation-wrapper.ts index ccbafa8c..bbd8ad4f 100644 --- a/src/aws/cloud-formation-wrapper.ts +++ b/src/aws/cloud-formation-wrapper.ts @@ -40,6 +40,7 @@ class CloudFormationWrapper { */ public async findApiId (apiType: string): Promise { const configApiId = await this.getConfigId(apiType); + console.log(`configApiId: ${configApiId}`); if (configApiId) { return configApiId; } @@ -112,7 +113,10 @@ class CloudFormationWrapper { } if (!response) { - throw new Error(`Failed to find a stack ${this.stackName}\n`); + throw new Error( + `Failed to find logicalResourceId '${logicalResourceId}' for the stack ${this.stackName}\n` + + "Make sure the stack exists and the API gateway event is added" + ); } const apiId = response.StackResourceDetail.PhysicalResourceId; diff --git a/test/unit-tests/aws/cloud-formation-wrapper.test.ts b/test/unit-tests/aws/cloud-formation-wrapper.test.ts index 1c47b01f..a42fc7cd 100644 --- a/test/unit-tests/aws/cloud-formation-wrapper.test.ts +++ b/test/unit-tests/aws/cloud-formation-wrapper.test.ts @@ -106,7 +106,7 @@ describe("Cloud Formation wrapper checks", () => { await new CloudFormationWrapper().findApiId(Globals.apiTypes.rest); } catch (err) { errored = true; - expect(err.message).to.contains("Failed to find a stack"); + expect(err.message).to.contains("Failed to find logicalResourceId"); } expect(errored).to.equal(true); @@ -159,7 +159,7 @@ describe("Cloud Formation wrapper checks", () => { await new CloudFormationWrapper().findApiId(Globals.apiTypes.rest); } catch (err) { errored = true; - expect(err.message).to.contains("Failed to find a stack"); + expect(err.message).to.contains("Failed to find logicalResourceId"); } expect(errored).to.equal(true); @@ -184,7 +184,7 @@ describe("Cloud Formation wrapper checks", () => { await new CloudFormationWrapper().findApiId(Globals.apiTypes.rest); } catch (err) { errored = true; - expect(err.message).to.contains("Failed to find a stack"); + expect(err.message).to.contains("Failed to find logicalResourceId"); } expect(errored).to.equal(true); expect(consoleOutput[0]).to.contains("Unsupported apiGateway"); @@ -388,7 +388,7 @@ describe("Cloud Formation wrapper checks", () => { await new CloudFormationWrapper().findApiId(Globals.apiTypes.rest); } catch (err) { errored = true; - expect(err.message).to.contains("Failed to find a stack"); + expect(err.message).to.contains("Failed to find logicalResourceId"); } expect(errored).to.equal(true); expect(consoleOutput[0]).to.contains("[WARNING] Failed to find CloudFormation resources with an error"); From e5cc1ae9026f72c2771f80bfb61bb12392f27390 Mon Sep 17 00:00:00 2001 From: rddimon Date: Thu, 7 Mar 2024 17:47:05 +0200 Subject: [PATCH 2/3] Remove console log --- src/aws/cloud-formation-wrapper.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/aws/cloud-formation-wrapper.ts b/src/aws/cloud-formation-wrapper.ts index bbd8ad4f..bd5cc115 100644 --- a/src/aws/cloud-formation-wrapper.ts +++ b/src/aws/cloud-formation-wrapper.ts @@ -40,7 +40,6 @@ class CloudFormationWrapper { */ public async findApiId (apiType: string): Promise { const configApiId = await this.getConfigId(apiType); - console.log(`configApiId: ${configApiId}`); if (configApiId) { return configApiId; } From a6c49a70482105a5ee1d975cc36c60d31329380d Mon Sep 17 00:00:00 2001 From: rddimon Date: Thu, 7 Mar 2024 17:48:15 +0200 Subject: [PATCH 3/3] Updated tests --- test/unit-tests/aws/cloud-formation-wrapper.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unit-tests/aws/cloud-formation-wrapper.test.ts b/test/unit-tests/aws/cloud-formation-wrapper.test.ts index a42fc7cd..8afed875 100644 --- a/test/unit-tests/aws/cloud-formation-wrapper.test.ts +++ b/test/unit-tests/aws/cloud-formation-wrapper.test.ts @@ -107,6 +107,7 @@ describe("Cloud Formation wrapper checks", () => { } catch (err) { errored = true; expect(err.message).to.contains("Failed to find logicalResourceId"); + expect(err.message).to.contains("Make sure the stack exists and the API gateway event is added"); } expect(errored).to.equal(true); @@ -160,6 +161,7 @@ describe("Cloud Formation wrapper checks", () => { } catch (err) { errored = true; expect(err.message).to.contains("Failed to find logicalResourceId"); + expect(err.message).to.contains("Make sure the stack exists and the API gateway event is added"); } expect(errored).to.equal(true); @@ -185,6 +187,7 @@ describe("Cloud Formation wrapper checks", () => { } catch (err) { errored = true; expect(err.message).to.contains("Failed to find logicalResourceId"); + expect(err.message).to.contains("Make sure the stack exists and the API gateway event is added"); } expect(errored).to.equal(true); expect(consoleOutput[0]).to.contains("Unsupported apiGateway"); @@ -389,6 +392,7 @@ describe("Cloud Formation wrapper checks", () => { } catch (err) { errored = true; expect(err.message).to.contains("Failed to find logicalResourceId"); + expect(err.message).to.contains("Make sure the stack exists and the API gateway event is added"); } expect(errored).to.equal(true); expect(consoleOutput[0]).to.contains("[WARNING] Failed to find CloudFormation resources with an error");