Files
rea/src/reference/ReferenceSourceReaderErrors.ts
T
679658b287 fix(reference): report entries beyond the path limit as I/O failures (#2716)
* fix(reference): report entries beyond the path limit as I/O failures

Reference-source traversal joins each child onto the root path. A valid
tree whose nested entries exceed the platform's absolute path limit
(PATH_MAX 1024 on macOS) makes lstat fail with ENAMETOOLONG. The
reader's filesystem error allow-list lacked that code, so
filesystemFailureDetail returned undefined and the native rejection
escaped both readReferenceSource and importReferenceSource instead of
becoming the existing failed `io` entry.

Add ENAMETOOLONG to the allow-list, matching the JavaScript application
reader's list. Readable siblings stay in the graph and the unreachable
entry is recorded with its OS message.

Fixes #2652

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(reference): assert the imported graph keeps readable and failed entries

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(process): report no remaining time after a provider deadline fires

Node timers can fire while performance.now() is still a fraction of a
millisecond short of the monotonic deadline. ProviderStartupDeadline then
reported interruption "timeout" and an aborted signal while remainingMs()
returned ceil(0.x) = 1, so polling loops guarded by remainingMs() > 0
(Hopper and Ghidra startup) could run past an elapsed deadline, and the
real-timer test "aborts a bounded wait when its real monotonic deadline
expires" failed intermittently in CI (expected 1 to be 0).

Once the deadline's own timer has classified a timeout, report zero
remaining time. A deterministic regression test fires the timer with the
monotonic clock 0.4 ms short of the deadline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(reference): preserve path limit entry uncertainty

* fix(reference): preserve unknown entry failures and identity

* fix(reference): type unknown-kind exclusions and keep them out of symlink counts

The metadata-failure path offers "unknown" to exclusion predicates, but
the predicate type only admitted concrete kinds, which broke the build.
Directory-only secret and ignore rules now also match an unknown-kind
entry (it may be a directory), and the summary counts unknown entries
separately instead of as symlinks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
Co-authored-by: Codex <codex@users.noreply.github.com>
2026-10-13 17:33:09 -07:00

93 lines
2.4 KiB
TypeScript

import type {
ReferenceSourceEntry,
ReferenceSourceFailureCode,
ReferenceSourceReaderError,
} from "./ReferenceSourceReaderTypes.js";
export const failure = (
code: ReferenceSourceReaderError["code"],
message: string,
): ReferenceSourceReaderError => ({
tag: "reference-source-reader",
code,
message,
});
export const cancelled = (): ReferenceSourceReaderError =>
failure("cancelled", "Reference source traversal cancelled");
export const safeSize = (size: bigint): number | undefined => {
const value = Number(size);
return Number.isSafeInteger(value) && value >= 0 ? value : undefined;
};
const FILESYSTEM_ERROR_CODES = new Set([
"EACCES",
"EBADF",
"EEXIST",
"EIO",
"EISDIR",
"ELOOP",
"EMFILE",
// A traversed child can exceed the platform's absolute path limit even
// though the selected root and every component are valid.
"ENAMETOOLONG",
"ENFILE",
"ENOENT",
"ENOTDIR",
"ENOSPC",
"EPERM",
"EROFS",
]);
/** Preserve actionable operating-system detail while leaving invariants visible. */
export const filesystemFailureDetail = (
cause: unknown,
operation: string,
): string | undefined => {
if (!(cause instanceof Error)) return undefined;
const code: unknown = Reflect.get(cause, "code");
if (code === "ENAMETOOLONG")
return `${operation}: ENAMETOOLONG (entry path exceeds the operating system path limit)`;
return typeof code === "string" && FILESYSTEM_ERROR_CODES.has(code)
? `${operation}: ${cause.message}`
: undefined;
};
/** Preserve root I/O detail while separating bad selections from access failures. */
export const rootFilesystemFailure = (
cause: unknown,
operation: string,
):
| {
readonly code: "invalid-root" | "io";
readonly message: string;
}
| undefined => {
if (!(cause instanceof Error)) return undefined;
const code: unknown = Reflect.get(cause, "code");
if (typeof code !== "string" || !FILESYSTEM_ERROR_CODES.has(code))
return undefined;
return {
code: code === "ENOENT" || code === "ENOTDIR" ? "invalid-root" : "io",
message: `${operation}: ${cause.message}`,
};
};
export const entryFailure = (
...[path, kind, code, message, size]: readonly [
string,
Extract<ReferenceSourceEntry, { status: "failed" }>["kind"],
ReferenceSourceFailureCode,
string,
size?: number,
]
): ReferenceSourceEntry => ({
status: "failed",
kind,
path,
code,
message,
...(size === undefined ? {} : { size }),
});