From 95b9a57078fc1361dfe1982477f22a28b84b58dd Mon Sep 17 00:00:00 2001 From: Shaun Stanworth Date: Wed, 23 Oct 2024 11:58:25 +0100 Subject: [PATCH] Further checks for environmental issues --- .../app/src/cli/services/function/binaries.ts | 2 +- .../cli-kit/src/public/node/error.test.ts | 8 ++++++++ packages/cli-kit/src/public/node/error.ts | 19 ++++++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/app/src/cli/services/function/binaries.ts b/packages/app/src/cli/services/function/binaries.ts index 59ab426406..9ef2a41041 100644 --- a/packages/app/src/cli/services/function/binaries.ts +++ b/packages/app/src/cli/services/function/binaries.ts @@ -125,7 +125,7 @@ export async function installBinary(bin: DownloadableBinary) { const outputStream = createFileWriteStream(tmpFile) await bin.processResponse(responseStream, outputStream) await chmod(tmpFile, 0o775) - await moveFile(tmpFile, bin.path) + await moveFile(tmpFile, bin.path, {overwrite: true}) }) }, async () => {}, diff --git a/packages/cli-kit/src/public/node/error.test.ts b/packages/cli-kit/src/public/node/error.test.ts index ff822cd8a9..7719967223 100644 --- a/packages/cli-kit/src/public/node/error.test.ts +++ b/packages/cli-kit/src/public/node/error.test.ts @@ -70,4 +70,12 @@ describe('shouldReportErrorAsUnexpected helper', () => { test('returns false for errors that imply environment issues', () => { expect(shouldReportErrorAsUnexpected(new Error('EPERM: operation not permitted, scandir'))).toBe(false) }) + + test('checks errors that have stack dependent environment issues', () => { + const error = new Error('Maximum call stack size exceeded') + expect(shouldReportErrorAsUnexpected(error)).toBe(true) + error.stack = `Error: Maximum call stack size exceeded +at node_modules/.pnpm/stubborn-fs@1.2.5/node_modules/stubborn-fs/dist/retryify.js:33:26 attempt` + expect(shouldReportErrorAsUnexpected(error)).toBe(false) + }) }) diff --git a/packages/cli-kit/src/public/node/error.ts b/packages/cli-kit/src/public/node/error.ts index af348c4d85..7a1cf4c94c 100644 --- a/packages/cli-kit/src/public/node/error.ts +++ b/packages/cli-kit/src/public/node/error.ts @@ -191,7 +191,7 @@ export function shouldReportErrorAsUnexpected(error: unknown): boolean { // this means its not one of the CLI wrapped errors if (error instanceof Error) { const message = error.message - return !errorMessageImpliesEnvironmentIssue(message) + return !errorMessageImpliesEnvironmentIssue(message, error.stack ?? '') } return true } @@ -217,20 +217,29 @@ export function cleanSingleStackTracePath(filePath: string): string { * There are certain errors that we know are not due to a CLI bug, but are environmental/user error. * * @param message - The error message to check. + * @param stack - The stack trace to check. * @returns A boolean indicating if the error message implies an environment issue. */ -function errorMessageImpliesEnvironmentIssue(message: string): boolean { +function errorMessageImpliesEnvironmentIssue(message: string, stack: string): boolean { const environmentIssueMessages = [ 'EPERM: operation not permitted, scandir', 'EACCES: permission denied', 'EPERM: operation not permitted, symlink', 'This version of npm supports the following node versions', - 'EBUSY: resource busy or locked, rmdir', + 'EBUSY: resource busy or locked', 'getaddrinfo ENOTFOUND', 'Client network socket disconnected before secure TLS connection was established', 'spawn EPERM', 'socket hang up', - ] - const anyMatches = environmentIssueMessages.some((issueMessage) => message.includes(issueMessage)) + 'ENOSPC: no space left on device', + ['Maximum call stack size exceeded', /stubborn-fs.*retryify/], + ] as const + const anyMatches = environmentIssueMessages.some((issueMessage) => { + if (typeof issueMessage === 'string') { + return message.includes(issueMessage) + } + const [messageCheck, stackCheck] = issueMessage + return message.includes(messageCheck) && stackCheck.test(stack) + }) return anyMatches }