From 9c503806c5efc3f1f4f06564cbbeea0d6b89633e Mon Sep 17 00:00:00 2001 From: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com> Date: Thu, 22 Aug 2024 23:44:26 +0200 Subject: [PATCH] make line endings in error mapper regex os independent (#1906) --- .changeset/fifty-carrots-study.md | 5 +++++ .../backend-deployer/src/cdk_error_mapper.ts | 21 ++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 .changeset/fifty-carrots-study.md diff --git a/.changeset/fifty-carrots-study.md b/.changeset/fifty-carrots-study.md new file mode 100644 index 0000000000..9a6e1f7193 --- /dev/null +++ b/.changeset/fifty-carrots-study.md @@ -0,0 +1,5 @@ +--- +'@aws-amplify/backend-deployer': patch +--- + +make line endings in error mapper regex os independent diff --git a/packages/backend-deployer/src/cdk_error_mapper.ts b/packages/backend-deployer/src/cdk_error_mapper.ts index 416188135d..a00715d08c 100644 --- a/packages/backend-deployer/src/cdk_error_mapper.ts +++ b/packages/backend-deployer/src/cdk_error_mapper.ts @@ -5,12 +5,12 @@ import { AmplifyUserError, } from '@aws-amplify/platform-core'; import { BackendDeployerOutputFormatter } from './types.js'; -import { EOL } from 'os'; /** * Transforms CDK error messages to human readable ones */ export class CdkErrorMapper { + private multiLineEolRegex = '[\r\n]+'; /** * Instantiate with a formatter that will be used for formatting CLI commands in error messages */ @@ -112,7 +112,7 @@ export class CdkErrorMapper { }, { errorRegex: new RegExp( - `(SyntaxError|ReferenceError|TypeError):((?:.|${EOL})*?at .*)` + `(SyntaxError|ReferenceError|TypeError):((?:.|${this.multiLineEolRegex})*?at .*)` ), humanReadableErrorMessage: 'Unable to build the Amplify backend definition.', @@ -140,7 +140,7 @@ export class CdkErrorMapper { }, { errorRegex: new RegExp( - `\\[ERR_MODULE_NOT_FOUND\\]:(.*)${EOL}|Error: Cannot find module (.*)` + `\\[ERR_MODULE_NOT_FOUND\\]:(.*)${this.multiLineEolRegex}|Error: Cannot find module (.*)` ), humanReadableErrorMessage: 'Cannot find module', resolutionMessage: @@ -160,7 +160,9 @@ export class CdkErrorMapper { }, { // Also extracts the first line in the stack where the error happened - errorRegex: new RegExp(`\\[esbuild Error\\]: ((?:.|${EOL})*?at .*)`), + errorRegex: new RegExp( + `\\[esbuild Error\\]: ((?:.|${this.multiLineEolRegex})*?at .*)` + ), humanReadableErrorMessage: 'Unable to build the Amplify backend definition.', resolutionMessage: @@ -170,7 +172,7 @@ export class CdkErrorMapper { }, { errorRegex: new RegExp( - `\\[TransformError\\]: Transform failed with .* error:${EOL}(?.*)` + `\\[TransformError\\]: Transform failed with .* error:${this.multiLineEolRegex}(?.*)` ), humanReadableErrorMessage: '{esBuildErrorMessage}', resolutionMessage: @@ -219,7 +221,10 @@ export class CdkErrorMapper { { // Error: .* is printed to stderr during cdk synth // Also extracts the first line in the stack where the error happened - errorRegex: new RegExp(`^Error: (.*${EOL}.*at.*)`, 'm'), + errorRegex: new RegExp( + `^Error: (.*${this.multiLineEolRegex}.*at.*)`, + 'm' + ), humanReadableErrorMessage: 'Unable to build the Amplify backend definition.', resolutionMessage: @@ -249,7 +254,9 @@ export class CdkErrorMapper { }, { // Note that the order matters, this should be the last as it captures generic CFN error - errorRegex: new RegExp(`Deployment failed: (.*)${EOL}`), + errorRegex: new RegExp( + `Deployment failed: (.*)${this.multiLineEolRegex}` + ), humanReadableErrorMessage: 'The CloudFormation deployment has failed.', resolutionMessage: 'Find more information in the CloudFormation AWS Console for this stack.',