mirror of
https://github.com/morluto/rea.git
synced 2026-10-31 11:56:12 +00:00
* refactor(domain): split error taxonomy into thematic modules Move each error family out of domain/errors.ts into its own module (base, core, provider selection/adapter, browser observation, artifact, evidence, unknown registry, hopper, configuration) and relocate AnalysisErrorProjection to analysisErrorProjection. Migrate all 162 importers to the owning modules and delete errors.ts. No re-export shims; behavior is unchanged. * refactor(runtime): name all silent catch causes without changing diagnostics Bind cause in every bare catch and unhandled rejection across src/. Real failures preserve the cause for logging; best-effort cleanup carries an explicit comment. Caller-visible and Evidence strings are byte-identical to before.
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { realpath, stat } from "node:fs/promises";
|
|
import { isAbsolute } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
/** Resolve one local file URL while rejecting remote hosts and encoded separators. */
|
|
export const authorizedElectronFile = async (
|
|
value: string,
|
|
): Promise<string | undefined> => {
|
|
if (/%(?:2f|5c)/iu.test(value)) return undefined;
|
|
let url: URL;
|
|
try {
|
|
url = new URL(value);
|
|
} catch (cause: unknown) {
|
|
// Non-URL input cannot authorize a local file.
|
|
void cause;
|
|
return undefined;
|
|
}
|
|
if (
|
|
url.protocol !== "file:" ||
|
|
url.hostname !== "" ||
|
|
url.username !== "" ||
|
|
url.password !== ""
|
|
)
|
|
return undefined;
|
|
let path: string;
|
|
try {
|
|
path = fileURLToPath(url);
|
|
} catch (cause: unknown) {
|
|
// Unconvertible file URLs cannot authorize a local file.
|
|
void cause;
|
|
return undefined;
|
|
}
|
|
if (!isAbsolute(path) || path.includes("\0")) return undefined;
|
|
let canonical: string;
|
|
try {
|
|
if (!(await stat(path)).isFile()) return undefined;
|
|
canonical = await realpath(path);
|
|
} catch (cause: unknown) {
|
|
// Missing or unreadable files cannot authorize a local file.
|
|
void cause;
|
|
return undefined;
|
|
}
|
|
return canonical;
|
|
};
|