From d51951ce6278d4b59deed938d65e1cb72b5102df Mon Sep 17 00:00:00 2001 From: Arsh <69170106+lilnasy@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:56:46 +0530 Subject: [PATCH] fix(cli): call path.replace only if it is a function (#10745) * fix(cli): call `path.replace` only if it is a function * add changeset --- .changeset/late-spoons-knock.md | 5 +++++ packages/astro/src/core/errors/dev/utils.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/late-spoons-knock.md diff --git a/.changeset/late-spoons-knock.md b/.changeset/late-spoons-knock.md new file mode 100644 index 000000000000..0cca6ce612f7 --- /dev/null +++ b/.changeset/late-spoons-knock.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes an issue where CLI commands could not report the reason for failure before exiting. diff --git a/packages/astro/src/core/errors/dev/utils.ts b/packages/astro/src/core/errors/dev/utils.ts index a61d1ee47c5a..f5de83de4758 100644 --- a/packages/astro/src/core/errors/dev/utils.ts +++ b/packages/astro/src/core/errors/dev/utils.ts @@ -174,7 +174,7 @@ function collectInfoFromStacktrace(error: SSRError & { stack: string }): StackIn stackText.split('\n').find((ln) => ln.includes('src') || ln.includes('node_modules')); // Disable eslint as we're not sure how to improve this regex yet // eslint-disable-next-line regexp/no-super-linear-backtracking - const source = possibleFilePath?.replace(/^[^(]+\(([^)]+).*$/, '$1').replace(/^\s+at\s+/, ''); + const source = possibleFilePath?.replace?.(/^[^(]+\(([^)]+).*$/, '$1').replace(/^\s+at\s+/, ''); let file = source?.replace(/:\d+/g, ''); const location = /:(\d+):(\d+)/.exec(source!) ?? [];