mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 13:41:17 -05:00
f40476265a
* refactor(reference): declare the reference-source reader's entry files for the import workflow * refactor(reference): keep traversal state, symlink reconciliation and entry failure helpers out of the declared entry files
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import type { ArtifactReaderFailure } from "../resources/index.js";
|
|
import { FILESYSTEM_ERROR_CODES } from "./ReferenceSourceReaderErrors.js";
|
|
import type { ReferenceSourceReaderError } from "./ReferenceSourceReaderTypes.js";
|
|
|
|
/** Project resource failures into the reference-source error contract. */
|
|
export const referenceSourceResourceFailure = (
|
|
cause: ArtifactReaderFailure,
|
|
): ReferenceSourceReaderError => ({
|
|
tag: "reference-source-reader",
|
|
code: cause.reason === "cancelled" ? "cancelled" : "io",
|
|
message: cause.message,
|
|
...(cause.cleanup === undefined ? {} : { cleanup: cause.cleanup }),
|
|
cause,
|
|
});
|
|
|
|
/** 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;
|
|
readonly remediationAction?: 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: ["ENOENT", "ENOTDIR", "ELOOP", "ENAMETOOLONG"].includes(code)
|
|
? "invalid-root"
|
|
: "io",
|
|
message: `${operation}: ${cause.message}`,
|
|
...(code === "ELOOP"
|
|
? {
|
|
remediationAction:
|
|
"Repair the symbolic-link chain or select another reference source directory.",
|
|
}
|
|
: code === "ENAMETOOLONG"
|
|
? {
|
|
remediationAction:
|
|
"Select a reference source path within the operating system's path-length limits.",
|
|
}
|
|
: {}),
|
|
};
|
|
};
|