Files
hyperframes/packages/core/src/missingPath.ts
T
Miguel Ángel a82ee10c68 feat(producer): a failed render says which file was gone again, looking only in its own folders (#8168)
* feat(producer): a render that fails on a missing file says what was gone again

Restores the diagnostic the previous commit on main took out, as it was; the commits after it confine what it looks at.

* test(producer): render failure diagnostics never probe a path from error text or outside the render

* fix(producer): probe a missing path only from a real error, inside the render's folders

describeMissingPath now reads only the path Node set on an ENOENT error, never
one quoted in a message the page can write, and looks on disk only under the
render's temp root, extract cache or work folder. Any other path is named from
its text, so a network share is never contacted and the facts cannot tell an
existing path from a missing one.

* test(producer): a missing-path probe never passes an outside link or climbs above its folder

* fix(producer): walk down from the render's own folder and check each link before following it

* build(producer): give the packed size budget its 5% headroom with the missing-file diagnostic back
2026-11-18 13:41:39 +00:00

26 lines
1.0 KiB
TypeScript

const quotedPath = (text: string) => /'([^']+)'/.exec(text)?.[1] ?? "";
function errorChain(error: unknown): Error[] {
const chain: Error[] = [];
for (let seen = error; seen instanceof Error && chain.length < 5; seen = seen.cause)
chain.push(seen);
return chain;
}
/** The path an ENOENT in `error` (or its causes) names, or undefined when nothing was missing. */
export function missingPathOf(error: unknown): string | undefined {
const enoent = errorChain(error).find(
(seen) => (seen as NodeJS.ErrnoException).code === "ENOENT",
);
if (enoent) return (enoent as NodeJS.ErrnoException).path ?? quotedPath(enoent.message);
const message = error instanceof Error ? error.message : String(error);
return /\bENOENT\b/.test(message) ? quotedPath(message) : undefined;
}
export function errnoMissingPathOf(error: unknown): string | undefined {
const enoent = errorChain(error).find(
(seen) => (seen as NodeJS.ErrnoException).code === "ENOENT",
) as NodeJS.ErrnoException | undefined;
return enoent?.path;
}