Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -604,6 +617,9 @@ describe("rethrowEnvironmentalGitError", () => {
),
),
).toBeNull();
expect(
capture(new Error("fatal: mmap failed: Cannot allocate memory\n")),
).toBeNull();
expect(
capture(
new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
Loading