Skip to content

Commit

Permalink
make line endings in error mapper regex os independent (#1906)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amplifiyer authored Aug 22, 2024
1 parent 5405c87 commit 9c50380
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-carrots-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/backend-deployer': patch
---

make line endings in error mapper regex os independent
21 changes: 14 additions & 7 deletions packages/backend-deployer/src/cdk_error_mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.',
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -170,7 +172,7 @@ export class CdkErrorMapper {
},
{
errorRegex: new RegExp(
`\\[TransformError\\]: Transform failed with .* error:${EOL}(?<esBuildErrorMessage>.*)`
`\\[TransformError\\]: Transform failed with .* error:${this.multiLineEolRegex}(?<esBuildErrorMessage>.*)`
),
humanReadableErrorMessage: '{esBuildErrorMessage}',
resolutionMessage:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.',
Expand Down

0 comments on commit 9c50380

Please sign in to comment.