From d583756cdb6d8012102a3a6e117e987e2e2da985 Mon Sep 17 00:00:00 2001 From: MJ Zhang <0618@users.noreply.github.com> Date: Wed, 15 May 2024 14:13:48 -0700 Subject: [PATCH] chore: log error for stackUpdateComplete (#13773) * chore: log error for stackUpdateComplete * Revert "chore: log error for stackUpdateComplete" This reverts commit 3972e9f9a8e114ceac59e375be0532f6ebcc4c33. * chore: log stackUpdateComplete message with errorDetails * chore: tweak stackUpdateComplete message with errorDetails * Update packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js Co-authored-by: Kamil Sobol * chore: import EOL from os * chore: change printAmplifyException instead of aws-cfn * Update packages/amplify-cli/src/amplify-exception-handler.ts Co-authored-by: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com> * chore: import EOL from os * test: fix amplify-exception-handler * test: fix amplify-exception-handler * chore: make test error mock content explicitly different --------- Co-authored-by: 0.618 Co-authored-by: Kamil Sobol Co-authored-by: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com> --- .../amplify-exception-handler.test.ts | 25 +++++++++++-------- .../src/amplify-exception-handler.ts | 7 +++--- 2 files changed, 19 insertions(+), 13 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..49d9efb2711 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'; @@ -56,30 +57,34 @@ 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); - expect(printerMock.info).toHaveBeenCalledWith(amplifyError.details); + expect(printerMock.error).toHaveBeenCalledWith(`${amplifyError.message}${EOL}${amplifyError.details}`); + expect(printerMock.info).toHaveBeenCalledTimes(2); + 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')); await handleException(amplifyError); - expect(printerMock.error).toHaveBeenCalledWith(amplifyError.message); - expect(printerMock.info).toHaveBeenCalledWith(amplifyError.details); + expect(printerMock.error).toHaveBeenCalledWith(`${amplifyError.message}${EOL}${amplifyError.details}`); + expect(printerMock.info).toHaveBeenCalledTimes(2); + 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'); }); diff --git a/packages/amplify-cli/src/amplify-exception-handler.ts b/packages/amplify-cli/src/amplify-exception-handler.ts index 7ff118dc00a..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, @@ -123,10 +124,10 @@ const executeSafely = async (functionToExecute: () => Promise | void, erro const printAmplifyException = (amplifyException: AmplifyException): void => { const { message, details, resolution, link, stack } = amplifyException; - - printer.error(message); if (details) { - printer.info(details); + printer.error(message + EOL + details); + } else { + printer.error(message); } printer.blankLine(); if (resolution) {