From 3972e9f9a8e114ceac59e375be0532f6ebcc4c33 Mon Sep 17 00:00:00 2001 From: "0.618" Date: Fri, 10 May 2024 10:48:04 -0700 Subject: [PATCH 01/12] chore: log error for stackUpdateComplete --- .../iterative-deployment/deployment-manager.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/amplify-provider-awscloudformation/src/iterative-deployment/deployment-manager.ts b/packages/amplify-provider-awscloudformation/src/iterative-deployment/deployment-manager.ts index 4477fd62458..55ad19c915f 100644 --- a/packages/amplify-provider-awscloudformation/src/iterative-deployment/deployment-manager.ts +++ b/packages/amplify-provider-awscloudformation/src/iterative-deployment/deployment-manager.ts @@ -490,9 +490,18 @@ export class DeploymentManager { assert(stackParams.stackName, 'stackName should be passed to waitForDeployment'); await cfnClient - .waitFor('stackUpdateComplete', { - StackName: stackParams.stackName, - }) + .waitFor( + 'stackUpdateComplete', + { + StackName: stackParams.stackName, + }, + (err, data) => { + if (err) { + throw err; + } + return data; + }, + ) .promise(); }; From 31304a842dcb6b636279362feb6d99072ebfbde7 Mon Sep 17 00:00:00 2001 From: "0.618" Date: Sat, 11 May 2024 13:43:18 -0700 Subject: [PATCH 02/12] Revert "chore: log error for stackUpdateComplete" This reverts commit 3972e9f9a8e114ceac59e375be0532f6ebcc4c33. --- .../iterative-deployment/deployment-manager.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/packages/amplify-provider-awscloudformation/src/iterative-deployment/deployment-manager.ts b/packages/amplify-provider-awscloudformation/src/iterative-deployment/deployment-manager.ts index 55ad19c915f..4477fd62458 100644 --- a/packages/amplify-provider-awscloudformation/src/iterative-deployment/deployment-manager.ts +++ b/packages/amplify-provider-awscloudformation/src/iterative-deployment/deployment-manager.ts @@ -490,18 +490,9 @@ export class DeploymentManager { assert(stackParams.stackName, 'stackName should be passed to waitForDeployment'); await cfnClient - .waitFor( - 'stackUpdateComplete', - { - StackName: stackParams.stackName, - }, - (err, data) => { - if (err) { - throw err; - } - return data; - }, - ) + .waitFor('stackUpdateComplete', { + StackName: stackParams.stackName, + }) .promise(); }; From 7e185338900ebdf70576dc364fa71d0b560abcf4 Mon Sep 17 00:00:00 2001 From: "0.618" Date: Sat, 11 May 2024 13:46:14 -0700 Subject: [PATCH 03/12] chore: log stackUpdateComplete message with errorDetails --- .../amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js b/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js index 5577b829b26..7a2093d72c3 100644 --- a/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js +++ b/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js @@ -418,7 +418,7 @@ class CloudFormation { if (completeErr) { await this.collectStackErrors(cfnParentStackParams.StackName).then((errorDetails) => { - completeErr.details = errorDetails; + completeErr.message = JSON.stringify(completeErr) + errorDetails; reject(completeErr); }); } else { From e725d194db1515a2541e255eff90d828fb25c82a Mon Sep 17 00:00:00 2001 From: "0.618" Date: Sat, 11 May 2024 14:06:26 -0700 Subject: [PATCH 04/12] chore: tweak stackUpdateComplete message with errorDetails --- .../amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js b/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js index 7a2093d72c3..2b0b99320f8 100644 --- a/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js +++ b/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js @@ -418,7 +418,7 @@ class CloudFormation { if (completeErr) { await this.collectStackErrors(cfnParentStackParams.StackName).then((errorDetails) => { - completeErr.message = JSON.stringify(completeErr) + errorDetails; + completeErr.message = `${completeErr.message} \n ${errorDetails}`; reject(completeErr); }); } else { From 6ac70a1895b84c39d77266eee45576dffd3008d5 Mon Sep 17 00:00:00 2001 From: MJ Zhang <0618@users.noreply.github.com> Date: Mon, 13 May 2024 10:00:05 -0700 Subject: [PATCH 05/12] Update packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js Co-authored-by: Kamil Sobol --- .../amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js b/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js index 2b0b99320f8..c3163321411 100644 --- a/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js +++ b/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js @@ -418,7 +418,7 @@ class CloudFormation { if (completeErr) { await this.collectStackErrors(cfnParentStackParams.StackName).then((errorDetails) => { - completeErr.message = `${completeErr.message} \n ${errorDetails}`; + completeErr.message = `${completeErr.message}${EOL}${errorDetails}`; reject(completeErr); }); } else { From 8f593706b2089286b0ade66a6090a18449cd1ae7 Mon Sep 17 00:00:00 2001 From: "0.618" Date: Mon, 13 May 2024 10:20:16 -0700 Subject: [PATCH 06/12] chore: import EOL from os --- .../amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js b/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js index c3163321411..c96fe4b0e0c 100644 --- a/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js +++ b/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js @@ -2,6 +2,7 @@ /* eslint-disable */ const fs = require('fs-extra'); const path = require('path'); +const { EOL } = require('os'); const _ = require('lodash'); const BottleNeck = require('bottleneck'); const chalk = require('chalk'); From 30aa596c9683e0398f69dd3acd68941e2aefb836 Mon Sep 17 00:00:00 2001 From: "0.618" Date: Mon, 13 May 2024 15:20:16 -0700 Subject: [PATCH 07/12] chore: change printAmplifyException instead of aws-cfn --- packages/amplify-cli/src/amplify-exception-handler.ts | 8 ++++++-- .../src/aws-utils/aws-cfn.js | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/amplify-cli/src/amplify-exception-handler.ts b/packages/amplify-cli/src/amplify-exception-handler.ts index 7ff118dc00a..1f4a859272f 100644 --- a/packages/amplify-cli/src/amplify-exception-handler.ts +++ b/packages/amplify-cli/src/amplify-exception-handler.ts @@ -123,8 +123,12 @@ const executeSafely = async (functionToExecute: () => Promise | void, erro const printAmplifyException = (amplifyException: AmplifyException): void => { const { message, details, resolution, link, stack } = amplifyException; - - printer.error(message); + if (message === 'Resource is not in the state stackUpdateComplete') { + // This change is to help Studio log more details to save another round of log analysis. + printer.error(message + details); + } else { + printer.error(message); + } if (details) { printer.info(details); } diff --git a/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js b/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js index c96fe4b0e0c..5577b829b26 100644 --- a/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js +++ b/packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js @@ -2,7 +2,6 @@ /* eslint-disable */ const fs = require('fs-extra'); const path = require('path'); -const { EOL } = require('os'); const _ = require('lodash'); const BottleNeck = require('bottleneck'); const chalk = require('chalk'); @@ -419,7 +418,7 @@ class CloudFormation { if (completeErr) { await this.collectStackErrors(cfnParentStackParams.StackName).then((errorDetails) => { - completeErr.message = `${completeErr.message}${EOL}${errorDetails}`; + completeErr.details = errorDetails; reject(completeErr); }); } else { From 7682b62f629eaf9dc6c08f9318e6d6246b0709e8 Mon Sep 17 00:00:00 2001 From: MJ Zhang <0618@users.noreply.github.com> Date: Tue, 14 May 2024 08:38:33 -0700 Subject: [PATCH 08/12] Update packages/amplify-cli/src/amplify-exception-handler.ts Co-authored-by: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com> --- packages/amplify-cli/src/amplify-exception-handler.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/amplify-cli/src/amplify-exception-handler.ts b/packages/amplify-cli/src/amplify-exception-handler.ts index 1f4a859272f..38b2ef3430f 100644 --- a/packages/amplify-cli/src/amplify-exception-handler.ts +++ b/packages/amplify-cli/src/amplify-exception-handler.ts @@ -123,15 +123,11 @@ const executeSafely = async (functionToExecute: () => Promise | void, erro const printAmplifyException = (amplifyException: AmplifyException): void => { const { message, details, resolution, link, stack } = amplifyException; - if (message === 'Resource is not in the state stackUpdateComplete') { - // This change is to help Studio log more details to save another round of log analysis. - printer.error(message + details); + if (details) { + printer.error(message + os.EOL + details); } else { printer.error(message); } - if (details) { - printer.info(details); - } printer.blankLine(); if (resolution) { printer.info(`Resolution: ${resolution}`); From bcb27aa066a060fa5d97cfc43ed889693837a96a Mon Sep 17 00:00:00 2001 From: "0.618" Date: Tue, 14 May 2024 11:08:17 -0700 Subject: [PATCH 09/12] chore: import EOL from os --- packages/amplify-cli/src/amplify-exception-handler.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/amplify-cli/src/amplify-exception-handler.ts b/packages/amplify-cli/src/amplify-exception-handler.ts index 38b2ef3430f..04b4c2f096c 100644 --- a/packages/amplify-cli/src/amplify-exception-handler.ts +++ b/packages/amplify-cli/src/amplify-exception-handler.ts @@ -1,3 +1,4 @@ +import { EOL } from 'os'; import { $TSAny, AmplifyException, @@ -124,7 +125,7 @@ const executeSafely = async (functionToExecute: () => Promise | void, erro const printAmplifyException = (amplifyException: AmplifyException): void => { const { message, details, resolution, link, stack } = amplifyException; if (details) { - printer.error(message + os.EOL + details); + printer.error(message + EOL + details); } else { printer.error(message); } From 0f2375d6c2023e75d173e6cb817108c3faf64912 Mon Sep 17 00:00:00 2001 From: "0.618" Date: Tue, 14 May 2024 13:09:00 -0700 Subject: [PATCH 10/12] test: fix amplify-exception-handler --- .../src/__tests__/amplify-exception-handler.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/amplify-cli/src/__tests__/amplify-exception-handler.test.ts b/packages/amplify-cli/src/__tests__/amplify-exception-handler.test.ts index 476106f2184..f36b7d58689 100644 --- a/packages/amplify-cli/src/__tests__/amplify-exception-handler.test.ts +++ b/packages/amplify-cli/src/__tests__/amplify-exception-handler.test.ts @@ -1,3 +1,4 @@ +import { EOL } from 'os'; import { AmplifyError } from '@aws-amplify/amplify-cli-core'; import { printer } from '@aws-amplify/amplify-prompts'; // eslint-disable-line import/no-extraneous-dependencies import { reportError } from '../commands/diagnose'; @@ -63,7 +64,7 @@ describe('test exception handler', () => { await handleException(amplifyError); - expect(printerMock.error).toHaveBeenCalledWith(amplifyError.message); + expect(printerMock.error).toHaveBeenCalledWith(`${amplifyError.message}${EOL}${amplifyError.details}`); expect(printerMock.info).toHaveBeenCalledWith(amplifyError.details); expect(printerMock.debug).toHaveBeenCalledWith(amplifyError.stack); }); @@ -78,7 +79,7 @@ describe('test exception handler', () => { reportErrorMock.mockRejectedValueOnce(new Error('MockTestError')); await handleException(amplifyError); - expect(printerMock.error).toHaveBeenCalledWith(amplifyError.message); + expect(printerMock.error).toHaveBeenCalledWith(`${amplifyError.message}${EOL}${amplifyError.details}`); expect(printerMock.info).toHaveBeenCalledWith(amplifyError.details); expect(printerMock.debug).toHaveBeenCalledWith(amplifyError.stack); expect(printerMock.error).toHaveBeenCalledWith('Failed to report error: MockTestError'); From db73695e42bb27f1e0d1c573cda7ed483d240bce Mon Sep 17 00:00:00 2001 From: "0.618" Date: Tue, 14 May 2024 17:40:20 -0700 Subject: [PATCH 11/12] test: fix amplify-exception-handler --- .../src/__tests__/amplify-exception-handler.test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/amplify-cli/src/__tests__/amplify-exception-handler.test.ts b/packages/amplify-cli/src/__tests__/amplify-exception-handler.test.ts index f36b7d58689..d41f6681161 100644 --- a/packages/amplify-cli/src/__tests__/amplify-exception-handler.test.ts +++ b/packages/amplify-cli/src/__tests__/amplify-exception-handler.test.ts @@ -65,7 +65,9 @@ describe('test exception handler', () => { await handleException(amplifyError); expect(printerMock.error).toHaveBeenCalledWith(`${amplifyError.message}${EOL}${amplifyError.details}`); - expect(printerMock.info).toHaveBeenCalledWith(amplifyError.details); + expect(printerMock.info).toHaveBeenCalledTimes(2); + expect(printerMock.info).toHaveBeenNthCalledWith(1, `Resolution: ${amplifyError.details}`); + expect(printerMock.info).toHaveBeenLastCalledWith('Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/'); expect(printerMock.debug).toHaveBeenCalledWith(amplifyError.stack); }); @@ -80,7 +82,9 @@ describe('test exception handler', () => { await handleException(amplifyError); expect(printerMock.error).toHaveBeenCalledWith(`${amplifyError.message}${EOL}${amplifyError.details}`); - expect(printerMock.info).toHaveBeenCalledWith(amplifyError.details); + expect(printerMock.info).toHaveBeenCalledTimes(2); + expect(printerMock.info).toHaveBeenNthCalledWith(1, `Resolution: ${amplifyError.details}`); + expect(printerMock.info).toHaveBeenLastCalledWith('Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/'); expect(printerMock.debug).toHaveBeenCalledWith(amplifyError.stack); expect(printerMock.error).toHaveBeenCalledWith('Failed to report error: MockTestError'); }); From 63146cf9f7e11071c7a03a85130b83f9c47b68b5 Mon Sep 17 00:00:00 2001 From: "0.618" Date: Wed, 15 May 2024 09:20:39 -0700 Subject: [PATCH 12/12] chore: make test error mock content explicitly different --- .../__tests__/amplify-exception-handler.test.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/amplify-cli/src/__tests__/amplify-exception-handler.test.ts b/packages/amplify-cli/src/__tests__/amplify-exception-handler.test.ts index d41f6681161..49d9efb2711 100644 --- a/packages/amplify-cli/src/__tests__/amplify-exception-handler.test.ts +++ b/packages/amplify-cli/src/__tests__/amplify-exception-handler.test.ts @@ -57,25 +57,25 @@ describe('test exception handler', () => { it('error handler should print error', async () => { const amplifyError = new AmplifyError('NotImplementedError', { - message: 'Test Not implemented', - details: 'Test Not implemented', - resolution: 'Test Not implemented', + message: 'Test Not implemented(message)', + details: 'Test Not implemented(details)', + resolution: 'Test Not implemented(resolution)', }); await handleException(amplifyError); expect(printerMock.error).toHaveBeenCalledWith(`${amplifyError.message}${EOL}${amplifyError.details}`); expect(printerMock.info).toHaveBeenCalledTimes(2); - expect(printerMock.info).toHaveBeenNthCalledWith(1, `Resolution: ${amplifyError.details}`); + expect(printerMock.info).toHaveBeenNthCalledWith(1, `Resolution: ${amplifyError.resolution}`); expect(printerMock.info).toHaveBeenLastCalledWith('Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/'); expect(printerMock.debug).toHaveBeenCalledWith(amplifyError.stack); }); it('error handler should handle encountered errors gracefully', async () => { const amplifyError = new AmplifyError('NotImplementedError', { - message: 'Test Not implemented', - details: 'Test Not implemented', - resolution: 'Test Not implemented', + message: 'Test Not implemented(message)', + details: 'Test Not implemented(details)', + resolution: 'Test Not implemented(resolution)', }); reportErrorMock.mockRejectedValueOnce(new Error('MockTestError')); @@ -83,7 +83,7 @@ describe('test exception handler', () => { expect(printerMock.error).toHaveBeenCalledWith(`${amplifyError.message}${EOL}${amplifyError.details}`); expect(printerMock.info).toHaveBeenCalledTimes(2); - expect(printerMock.info).toHaveBeenNthCalledWith(1, `Resolution: ${amplifyError.details}`); + expect(printerMock.info).toHaveBeenNthCalledWith(1, `Resolution: ${amplifyError.resolution}`); expect(printerMock.info).toHaveBeenLastCalledWith('Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/'); expect(printerMock.debug).toHaveBeenCalledWith(amplifyError.stack); expect(printerMock.error).toHaveBeenCalledWith('Failed to report error: MockTestError');