diff --git a/packages/host-service/src/trpc/router/git/utils/classify-git-error.test.ts b/packages/host-service/src/trpc/router/git/utils/classify-git-error.test.ts index c2312f80b47..be136b8a10c 100644 --- a/packages/host-service/src/trpc/router/git/utils/classify-git-error.test.ts +++ b/packages/host-service/src/trpc/router/git/utils/classify-git-error.test.ts @@ -596,6 +596,19 @@ describe("rethrowEnvironmentalGitError", () => { ).toBe("GIT_ENVIRONMENT"); }); + test("object or worktree file its storage cannot deliver → PRECONDITION_FAILED / GIT_ENVIRONMENT", () => { + const canceled = "fatal: mmap failed: Operation canceled\n"; + const thrown = capture(new Error(canceled)); + expect(thrown?.code).toBe("PRECONDITION_FAILED"); + expect(causeKind(thrown)).toBe("GIT_ENVIRONMENT"); + expect(thrown?.message).toBe(canceled); + expect( + causeKind( + capture(new Error("fatal: mmap failed: Operation timed out\n")), + ), + ).toBe("GIT_ENVIRONMENT"); + }); + test("does not claim other index mapping failures or network timeouts", () => { expect( capture( @@ -604,6 +617,9 @@ describe("rethrowEnvironmentalGitError", () => { ), ), ).toBeNull(); + expect( + capture(new Error("fatal: mmap failed: Cannot allocate memory\n")), + ).toBeNull(); expect( capture( new Error( diff --git a/packages/host-service/src/trpc/router/git/utils/classify-git-error.ts b/packages/host-service/src/trpc/router/git/utils/classify-git-error.ts index d655eac768b..67117e494e4 100644 --- a/packages/host-service/src/trpc/router/git/utils/classify-git-error.ts +++ b/packages/host-service/src/trpc/router/git/utils/classify-git-error.ts @@ -20,6 +20,10 @@ const NOT_GIT_REPO_PATTERN = // such as running out of memory, stay unclassified. const INDEX_STORAGE_UNAVAILABLE_PATTERN = /unable to map index file: Operation (?:timed out|canceled)$/m; +// The same storage failure on any other file git maps (packfiles, pack +// indexes, worktree files it hashes), reported by git's xmmap() wrapper. +const MAPPED_FILE_STORAGE_UNAVAILABLE_PATTERN = + /^fatal: mmap failed: Operation (?:timed out|canceled)$/m; // Git's text when the directory resolves to a repository but has no work tree // attached: the repo is bare, or the linked worktree's admin data was removed // or pruned. Distinct from CWD_GONE_PATTERN, where the directory itself is @@ -147,7 +151,8 @@ export function rethrowEnvironmentalGitError(error: unknown): void { } if ( CWD_UNREADABLE_PATTERN.test(error.message) || - INDEX_STORAGE_UNAVAILABLE_PATTERN.test(error.message) + INDEX_STORAGE_UNAVAILABLE_PATTERN.test(error.message) || + MAPPED_FILE_STORAGE_UNAVAILABLE_PATTERN.test(error.message) ) { throw new TRPCError({ code: "PRECONDITION_FAILED",