refactor(runtime): name all silent catch causes without changing diagnostics (#637)

* 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.
This commit is contained in:
morluto
2026-10-06 05:58:46 +08:00
committed by GitHub
parent 735c10059c
commit 5f27e02fae
65 changed files with 363 additions and 131 deletions
@@ -41,7 +41,8 @@ export const evaluateAnalysisProviderCandidate = async (
if (resolution === ABORTED)
return err(new AnalysisCancelledError("open_binary"));
resolved = resolution;
} catch {
} catch (cause: unknown) {
void cause;
return ok(
rejectedProfile(candidate, status, "Provider profile resolution threw"),
);
@@ -82,7 +83,8 @@ export const evaluateAnalysisProviderCandidate = async (
),
);
return ok({ candidate, status, profile, compatibility });
} catch {
} catch (cause: unknown) {
void cause;
return ok(
rejectedProfile(
candidate,
+5 -1
View File
@@ -171,7 +171,11 @@ const materializeSelection = async ({
await output.commit();
return result;
} catch (cause: unknown) {
if (!readerClosed) await reader.close().catch(() => undefined);
if (!readerClosed)
await reader.close().catch((cause: unknown) => {
// best-effort cleanup: reader close must not mask the extraction failure.
void cause;
});
await output.rollback();
throw cause;
}
+6 -2
View File
@@ -186,10 +186,14 @@ export abstract class BinarySessionRecords {
try {
const notification = listener();
if (notification !== undefined)
void notification.catch(() => undefined);
} catch {
void notification.catch((cause: unknown) => {
// best-effort cleanup: async observer notifications must not reject unhandled.
void cause;
});
} catch (cause: unknown) {
// External resource observers are best-effort; one callback must not
// make a committed evidence mutation appear to fail.
void cause;
}
}
}
+3 -1
View File
@@ -44,7 +44,9 @@ export const resolveClientConfigTransactionPath = async (
return targetStats.isFile?.() === true && targetStats.uid === currentUid
? canonicalPath
: undefined;
} catch {
} catch (cause: unknown) {
// best-effort cleanup: unreadable or vanishing config paths mean no registration.
void cause;
return undefined;
}
};
+3 -1
View File
@@ -226,7 +226,9 @@ const exists = async (path: string | undefined): Promise<boolean> => {
try {
await access(path);
return true;
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional registration probing; absence means unregistered.
void cause;
return false;
}
};
+20 -7
View File
@@ -353,7 +353,9 @@ export const systemDoctorHost = (
)
).stdout.trim();
return `${prefix}/Hopper Disassembler.app/Contents/MacOS/hopper`;
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional Homebrew probing; absence means uninstalled.
void cause;
return undefined;
}
});
@@ -373,7 +375,9 @@ export const systemDoctorHost = (
})
).stdout,
);
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional version probing; failure means unavailable.
void cause;
return undefined;
}
},
@@ -385,7 +389,9 @@ export const systemDoctorHost = (
(await hostExecFileOutput(command, arguments_, commandEnvironment))
.stdout,
);
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional path probing; failure means none found.
void cause;
return [];
}
},
@@ -404,7 +410,9 @@ const readMacosVersion = async (
): Promise<string | undefined> => {
try {
return (await run("sw_vers", ["-productVersion"], options)).stdout.trim();
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional OS version probing; failure means unknown.
void cause;
return undefined;
}
};
@@ -420,7 +428,9 @@ const executableAvailable = async (
if (platform !== "linux") return true;
const linked = await run("ldd", [path], options);
return linuxSharedLibrariesAvailable(`${linked.stdout}\n${linked.stderr}`);
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional executable probing; failure means unavailable.
void cause;
return false;
}
};
@@ -444,8 +454,9 @@ const manualHopperPaths = async (
if (entry.isDirectory() && /^Hopper.*\.app$/i.test(entry.name))
paths.push(join(root, entry.name, "Contents/MacOS/hopper"));
}
} catch {
} catch (cause: unknown) {
// A missing or unreadable optional application directory is not fatal.
void cause;
}
}
return paths;
@@ -471,7 +482,9 @@ const installedSkillIdentity = async (
/^\s{2}catalog_digest:\s*"([a-f0-9]{64})"\s*$/mu.exec(content)?.[1] ??
null,
};
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional skill probing; failure means unknown.
void cause;
return undefined;
}
};
@@ -157,7 +157,8 @@ const parsePackage = (
let value: unknown;
try {
value = JSON.parse(file.text.value);
} catch {
} catch (cause: unknown) {
void cause;
return invalidPackage(file, "package.json is not valid JSON.");
}
if (!isRecord(value))
@@ -232,7 +233,8 @@ const parseSourceMap = (
let value: unknown;
try {
value = JSON.parse(file.text.value);
} catch {
} catch (cause: unknown) {
void cause;
return invalidSourceMap(file, "Source map is not valid JSON.");
}
const maps = flattenSourceMaps(value);
+3 -1
View File
@@ -232,7 +232,9 @@ const readText = async (
included: true,
value: new TextDecoder("utf-8", { fatal: true }).decode(bytes),
};
} catch {
} catch (cause: unknown) {
// Non-UTF8 bytes are counted; the fixed reason preserves the schema.
void cause;
context.invalidUtf8 += 1;
return { included: false, reason: "invalid-utf8" };
}
@@ -430,7 +430,9 @@ const packageEntry = (
if (entry === undefined) return { status: "missing" };
const legacy = packagePathValue(entry);
return legacy.status === "value" ? { ...legacy, source: "legacy" } : legacy;
} catch {
} catch (cause: unknown) {
// Reflect-based manifest reads fail closed as invalid.
void cause;
return { status: "invalid" };
}
};
@@ -545,7 +547,9 @@ const fileUrlPath = (value: string): string | undefined => {
const url = new URL(value);
if (url.protocol !== "file:" || url.hostname !== "") return undefined;
return decodeURIComponent(url.pathname).replace(/^\/+/, "");
} catch {
} catch (cause: unknown) {
// Unparseable file URLs have no path to resolve.
void cause;
return undefined;
}
};
+2 -1
View File
@@ -18,7 +18,8 @@ export const analyzeJavaScriptJsonModule = (
let value: unknown;
try {
value = JSON.parse(file.text.value);
} catch {
} catch (cause: unknown) {
void cause;
return {
path: file.path,
sha256: file.sha256,
@@ -401,7 +401,9 @@ const jsonStatus = (
try {
JSON.parse(file.text.value);
return "included";
} catch {
} catch (cause: unknown) {
// Invalid JSON is classified without further detail.
void cause;
return "invalid";
}
};
+12 -4
View File
@@ -165,7 +165,9 @@ export const readLinuxDistribution = async (): Promise<
> => {
try {
return parseLinuxDistribution(await readFile("/etc/os-release", "utf8"));
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional host probing; unknown distribution means unsupported.
void cause;
return undefined;
}
};
@@ -244,7 +246,9 @@ const systemLinuxHopperInstallHost = (): LinuxHopperInstallHost => ({
return (await linuxHopperBinarySupported(path))
? "ready"
: "unsupported_hopper_build";
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional launcher probing; unreadable means missing.
void cause;
return "missing";
}
},
@@ -259,7 +263,9 @@ export const linuxHopperBinarySupported = async (
const hash = createHash("sha256");
for await (const chunk of createReadStream(path)) hash.update(chunk);
return hash.digest("hex") === SUPPORTED_HOPPER_SHA256;
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional build probing; unreadable means unsupported.
void cause;
return false;
}
};
@@ -280,7 +286,9 @@ const installSystemPackage = async (
))
await execFileAsync(command.executable, command.args);
return true;
} catch {
} catch (cause: unknown) {
// Package-manager failure is reported by the false return.
void cause;
return false;
}
};
+20 -7
View File
@@ -120,7 +120,9 @@ export const installMacHopper = async (
return { status: "failed", reason: "launcher_missing" };
await host.openApplication(destination);
return { status: "installed", launcherPath };
} catch {
} catch (cause: unknown) {
// Install-stage failures share the download reason; the stage is cleaned below.
void cause;
return { status: "failed", reason: "download" };
} finally {
if (temporary !== undefined) {
@@ -175,7 +177,9 @@ const systemMacHopperInstallHost = (): MacHopperInstallHost => ({
])
).stdout.trim();
return identifier === BUNDLE_IDENTIFIER;
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional bundle probing; unreadable means invalid.
void cause;
return false;
}
},
@@ -183,7 +187,9 @@ const systemMacHopperInstallHost = (): MacHopperInstallHost => ({
try {
await access(path);
return true;
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional existence probing; absence means missing.
void cause;
return false;
}
},
@@ -199,13 +205,16 @@ const systemMacHopperInstallHost = (): MacHopperInstallHost => ({
await rename(stage, destination);
if (replaceExisting) await rm(previous, { recursive: true, force: true });
return true;
} catch {
} catch (cause: unknown) {
// Install failure rolls back below; the false return reports it.
void cause;
await rm(stage, { recursive: true, force: true });
if (replaceExisting) {
try {
await rename(previous, destination);
} catch {
} catch (rollbackCause: unknown) {
// The original destination was not moved, or rollback is impossible.
void rollbackCause;
}
}
return false;
@@ -215,7 +224,9 @@ const systemMacHopperInstallHost = (): MacHopperInstallHost => ({
try {
await access(path);
return true;
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional launcher probing; absence means not ready.
void cause;
return false;
}
},
@@ -253,7 +264,9 @@ const commandSucceeds = async (
try {
await execFileAsync(command, args);
return true;
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional command probing; failure means unavailable.
void cause;
return false;
}
};
+3 -1
View File
@@ -72,7 +72,9 @@ export const scheduleScenarioInteractions = (
),
);
} else terminal.kill(event.signal);
} catch {
} catch (cause: unknown) {
// Terminal dispatch failures are recorded as failed outcomes.
void cause;
outcome = "failed";
}
}
+4 -2
View File
@@ -362,7 +362,8 @@ export const releaseProcessResources = async (options: {
let failure: string | undefined;
try {
await options.renderer?.dispose();
} catch {
} catch (cause: unknown) {
void cause;
failure ??= "terminal renderer cleanup failed";
}
if (options.terminal !== undefined && host.platform !== "win32") {
@@ -377,7 +378,8 @@ export const releaseProcessResources = async (options: {
}
try {
await host.removeTemporaryRoot(options.temporaryRoot);
} catch {
} catch (cause: unknown) {
void cause;
failure ??= "temporary process root cleanup failed";
}
return failure;
+6 -4
View File
@@ -112,7 +112,7 @@ const parseCaptureEvidence = (input: unknown) => {
let evidence;
try {
evidence = parseEvidence(input);
} catch {
} catch (cause: unknown) {
throw invalidCaptureEvidence();
}
if (
@@ -132,7 +132,7 @@ const parseCaptureEvidence = (input: unknown) => {
capture: parseProcessCapture(evidence.normalized_result),
locations: evidence.locations,
};
} catch {
} catch (cause: unknown) {
throw invalidCaptureEvidence();
}
};
@@ -157,7 +157,8 @@ const readJson = async (path: string): Promise<unknown> => {
let bytes;
try {
bytes = await readFile(path);
} catch {
} catch (cause: unknown) {
void cause;
throw new ProcessCliFailure(
"invalid_input",
"Process input file could not be read. Check that the path exists and is readable.",
@@ -166,7 +167,8 @@ const readJson = async (path: string): Promise<unknown> => {
try {
const parsed: unknown = JSON.parse(bytes.toString("utf8"));
return parsed;
} catch {
} catch (cause: unknown) {
void cause;
throw new ProcessCliFailure(
"invalid_input",
"Process input file is not valid JSON. Repair the file, then try again.",
+3 -1
View File
@@ -358,7 +358,9 @@ const inspectInitializedPtyRoot = async (
let observedRunId: string | undefined;
try {
observedRunId = await readProcessRunId(rootPid);
} catch {
} catch (cause: unknown) {
// Unreadable run identity means the root cannot be attributed.
void cause;
return undefined;
}
const after = await readRootIdentity(rootPid, signal);
@@ -36,7 +36,8 @@ const resolveRoot = async (
);
const canonicalRoot = await realpath(resolve(requestedRoot));
return ok(canonicalRoot);
} catch {
} catch (cause: unknown) {
void cause;
return err(
failure("invalid-root", "Reference source root could not be resolved"),
);
@@ -50,8 +51,9 @@ const buildIgnored = async (
const ignored = ignore();
try {
ignored.add(await readFile(join(root, ".gitignore"), "utf8"));
} catch {
} catch (cause: unknown) {
// Missing or unreadable ignore file does not authorize broader access.
void cause;
}
ignored.add([...DEFAULT_REFERENCE_SOURCE_IGNORE_PATTERNS]);
for (const path of excludePaths) {
+3 -1
View File
@@ -34,7 +34,9 @@ export const readReferenceSourceVcs = async (
const head = await resolveRef({ fs, dir: root, ref: "HEAD" });
if (isAborted(signal)) return { kind: "unknown", head: null, dirty: null };
return { kind: "git", head, dirty: null };
} catch {
} catch (cause: unknown) {
// Unresolvable refs mean VCS state is unknown, not absent.
void cause;
return { kind: "unknown", head: null, dirty: null };
}
};
+17 -6
View File
@@ -77,7 +77,9 @@ const configureClientDocument = async (
original ?? (format === "toml" ? "" : "{}"),
format,
);
} catch {
} catch (cause: unknown) {
// Malformed existing configuration fails the readback gate.
void cause;
return { status: "failed", reason: "readback" };
}
const { document, servers, serversKey } = parsed;
@@ -120,7 +122,9 @@ const configureClientDocument = async (
mode: 0o600,
},
);
} catch {
} catch (cause: unknown) {
// Write failure is reported by the status reason.
void cause;
return { status: "failed", reason: "write" };
}
try {
@@ -137,7 +141,9 @@ const configureClientDocument = async (
await restoreConfig(transactionPath, original);
return { status: "failed", reason: "readback" };
}
} catch {
} catch (cause: unknown) {
// Readback failure restores the transaction before reporting.
void cause;
await restoreConfig(transactionPath, original);
return { status: "failed", reason: "readback" };
}
@@ -166,7 +172,9 @@ export const clientConfigurationAligned = async (
servers[PRODUCT_IDENTITY.mcpServerKey],
desired,
);
} catch {
} catch (cause: unknown) {
// Unreadable configuration is treated as not aligned so setup repairs it.
void cause;
return false;
}
};
@@ -213,7 +221,9 @@ export const inspectClientConfiguration = async (
)
)
return { status: "already_current" };
} catch {
} catch (cause: unknown) {
// Malformed configuration is reported with the invalid remediation.
void cause;
return {
status: "invalid",
remediation:
@@ -247,8 +257,9 @@ const restoreConfig = async (
try {
if (original === undefined) await rm(path, { force: true });
else await writeFile(path, original, { encoding: "utf8", mode: 0o600 });
} catch {
} catch (cause: unknown) {
// The backup remains available for the remediation reported by setup.
void cause;
}
};
+3 -1
View File
@@ -143,7 +143,9 @@ const exists = async (path: string): Promise<boolean> => {
try {
await access(path);
return true;
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional host probing; absence means unavailable.
void cause;
return false;
}
};
+8 -3
View File
@@ -59,7 +59,9 @@ export const canonicalSkillNeedsInstall = async (
return (await canonicalSkillFiles(home)).some(
({ content, original }) => original !== content,
);
} catch {
} catch (cause: unknown) {
// Unreadable skill state fails open to install so setup can repair it.
void cause;
return true;
}
};
@@ -97,11 +99,14 @@ export const installCanonicalSkill = async (
if ((await readFile(destination, "utf8")) !== content)
throw new Error(`skill readback mismatch: ${destination}`);
return "installed";
} catch {
} catch (cause: unknown) {
// Install failure preserves the original error outcome; report cause inline.
void cause;
try {
await restoreSkillFiles(changed);
} catch {
} catch (restoreCause: unknown) {
// Per-file backups remain beside changed files for operator recovery.
void restoreCause;
}
return "failed";
}
+7 -2
View File
@@ -50,7 +50,10 @@ export const createStoreFileLock = async (
}
return {
release: async () => {
await removeOwner(path, owner).catch(() => undefined);
await removeOwner(path, owner).catch((cause: unknown) => {
// best-effort cleanup: lock release must not reject unhandled.
void cause;
});
},
};
} finally {
@@ -85,7 +88,9 @@ export const removeStaleStoreFileLock = async (
return false;
await removeOwner(path, owner);
return true;
} catch {
} catch (cause: unknown) {
// best-effort cleanup: stale lock probing; failure means the lock stands.
void cause;
return false;
}
};
+9 -4
View File
@@ -150,7 +150,8 @@ const removeClient = async (
servers,
serversKey: key,
} = parseClientConfiguration(original, client.format));
} catch {
} catch (cause: unknown) {
void cause;
return item(
client.name,
"failed",
@@ -172,7 +173,8 @@ const removeClient = async (
const backupPath = `${client.configPath}.rea.backup`;
try {
await fileSystem.copy(transactionPath, backupPath);
} catch {
} catch (cause: unknown) {
void cause;
return item(
client.name,
"failed",
@@ -200,10 +202,13 @@ const removeClient = async (
"removed",
`Removed registration from ${client.configPath}.`,
);
} catch {
} catch (cause: unknown) {
// Update failure attempts a restore before reporting; cause is preserved below.
void cause;
try {
await fileSystem.writeText(transactionPath, original);
} catch {
} catch (restoreCause: unknown) {
void restoreCause;
return item(
client.name,
"failed",
+5 -2
View File
@@ -85,7 +85,9 @@ export const detectNpmInstallation = async (
let canonicalPackageRoot: string;
try {
canonicalPackageRoot = await host.canonicalPath(packageRoot);
} catch {
} catch (cause: unknown) {
// best-effort cleanup: optional install-location probing; unknown means not npm-managed.
void cause;
return undefined;
}
try {
@@ -99,8 +101,9 @@ export const detectNpmInstallation = async (
? undefined
: { prefix, packageRoot: canonicalPackageRoot };
}
} catch {
} catch (cause: unknown) {
// The curl installer uses a Unix prefix that may differ from npm's current default.
void cause;
}
const nodeModules = dirname(canonicalPackageRoot);
const library = dirname(nodeModules);
+2 -1
View File
@@ -126,9 +126,10 @@ const probeSymlinkCreation = async (): Promise<WindowsCapabilityOutcome> => {
} finally {
try {
await rm(root, { recursive: true, force: true });
} catch {
} catch (cause: unknown) {
// Cleanup failure must not replace the machine-readable probe outcome.
// The probe root lives beneath the OS temporary directory and is unique.
void cause;
}
}
};