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:
@@ -141,7 +141,9 @@ const readDevtoolsPort = async (path: string): Promise<number | null> => {
|
||||
return Number.isSafeInteger(port) && port > 0 && port <= 65_535
|
||||
? port
|
||||
: null;
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Missing or unreadable port files mean the port is unknown.
|
||||
void cause;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -433,7 +433,9 @@ const domDestination = (
|
||||
url: allowedSanitizedUrl(parsed.href, allowedOrigins)?.url ?? null,
|
||||
scope: "approved",
|
||||
};
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Unparseable URLs are out of scope, not failures.
|
||||
void cause;
|
||||
return { url: null, scope: "unsupported" };
|
||||
}
|
||||
};
|
||||
|
||||
@@ -98,7 +98,9 @@ const sourceMapForScript = (
|
||||
let rawUrl: string;
|
||||
try {
|
||||
rawUrl = new URL(declaredUrl, scriptUrl).href;
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Unparseable URLs are recorded as unsupported, not as failures.
|
||||
void cause;
|
||||
state.completeness.exclude("source_maps", "unsupported_url");
|
||||
return { sanitized: null, raw: null };
|
||||
}
|
||||
@@ -344,7 +346,9 @@ export const handleWebSocketCreated = (
|
||||
let parsed: URL;
|
||||
try {
|
||||
parsed = new URL(rawUrl);
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Unparseable URLs are recorded as unsupported, not as failures.
|
||||
void cause;
|
||||
state.completeness.exclude("websocket_connections", "unsupported_url");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,9 @@ export const isHttpUrl = (value: string | undefined): boolean => {
|
||||
try {
|
||||
const protocol = new URL(value).protocol;
|
||||
return protocol === "http:" || protocol === "https:";
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Non-URL input is not an HTTP URL.
|
||||
void cause;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -116,7 +116,9 @@ const sanitizeTargetTitle = (value: string, targetUrl: string): string => {
|
||||
let url: URL;
|
||||
try {
|
||||
url = new URL(value);
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Non-URL titles fall back to alias redaction.
|
||||
void cause;
|
||||
return sanitizeTargetUrlAlias(value, targetUrl);
|
||||
}
|
||||
return url.protocol === "http:" || url.protocol === "https:"
|
||||
@@ -128,7 +130,9 @@ const sanitizeTargetUrlAlias = (value: string, targetUrl: string): string => {
|
||||
let parsed: URL;
|
||||
try {
|
||||
parsed = new URL(targetUrl);
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Without a parseable target URL there is nothing to redact.
|
||||
void cause;
|
||||
return value;
|
||||
}
|
||||
const markers = [parsed.origin, `//${parsed.host}`, parsed.host];
|
||||
@@ -150,7 +154,9 @@ const sanitizeSameOriginTitleUrl = (candidate: string, target: URL): string => {
|
||||
: candidate.startsWith(target.host)
|
||||
? new URL(`${target.protocol}//${candidate}`)
|
||||
: new URL(candidate, target.origin);
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Unparseable candidates are preserved verbatim.
|
||||
void cause;
|
||||
return candidate;
|
||||
}
|
||||
return parsed.origin === target.origin &&
|
||||
@@ -273,7 +279,9 @@ const targetWebSocket = (
|
||||
return webSocket.scope === "page" && webSocket.targetId === target.id
|
||||
? { webSocket }
|
||||
: {};
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Endpoint validation failures mean no validated transport exists.
|
||||
void cause;
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -130,7 +130,9 @@ const cspSource = (
|
||||
return allowedOrigins.has(parsed.origin)
|
||||
? { kind: "approved_origin", value: parsed.origin }
|
||||
: { kind: "external_origin", value: null };
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Non-URL tokens are classified as other.
|
||||
void cause;
|
||||
return { kind: "other", value: null };
|
||||
}
|
||||
};
|
||||
@@ -210,7 +212,9 @@ const safeDestination = (
|
||||
if (!allowedOrigins.has(parsed.origin))
|
||||
return { url: sanitized, scope: "outside_policy" };
|
||||
return { url: sanitized, scope: "approved" };
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Unparseable link values keep their raw text for the analyst.
|
||||
void cause;
|
||||
return { url: value, scope: "unsupported" };
|
||||
}
|
||||
};
|
||||
@@ -231,7 +235,9 @@ const wellKnownHint = (url: string): AgentHint[] => {
|
||||
return wellKnownAgentPaths.has(path)
|
||||
? [agentHint("well_known_resource", path, sanitizeBrowserUrl(url).url)]
|
||||
: [];
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Non-URL input yields no well-known hint.
|
||||
void cause;
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,7 +10,9 @@ export const authorizedElectronFile = async (
|
||||
let url: URL;
|
||||
try {
|
||||
url = new URL(value);
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Non-URL input cannot authorize a local file.
|
||||
void cause;
|
||||
return undefined;
|
||||
}
|
||||
if (
|
||||
@@ -23,7 +25,9 @@ export const authorizedElectronFile = async (
|
||||
let path: string;
|
||||
try {
|
||||
path = fileURLToPath(url);
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Unconvertible file URLs cannot authorize a local file.
|
||||
void cause;
|
||||
return undefined;
|
||||
}
|
||||
if (!isAbsolute(path) || path.includes("\0")) return undefined;
|
||||
@@ -31,7 +35,9 @@ export const authorizedElectronFile = async (
|
||||
try {
|
||||
if (!(await stat(path)).isFile()) return undefined;
|
||||
canonical = await realpath(path);
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Missing or unreadable files cannot authorize a local file.
|
||||
void cause;
|
||||
return undefined;
|
||||
}
|
||||
return canonical;
|
||||
|
||||
@@ -35,7 +35,9 @@ export const authorizeRuntimeLocation = async (
|
||||
let url: URL;
|
||||
try {
|
||||
url = new URL(value);
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Non-URL input is outside the authorized runtime scope.
|
||||
void cause;
|
||||
return { allowed: false, reason: "unsupported_location" };
|
||||
}
|
||||
if (!["http:", "https:"].includes(url.protocol))
|
||||
|
||||
@@ -60,7 +60,8 @@ const captureScreenshot = async (page: Page) => {
|
||||
data_base64: bytes.toString("base64"),
|
||||
},
|
||||
};
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
void cause;
|
||||
return missing("screenshot capture failed");
|
||||
}
|
||||
};
|
||||
@@ -72,7 +73,8 @@ const captureDom = async (input: {
|
||||
const { page, secrets } = input;
|
||||
try {
|
||||
return textArtifact(secrets.redact(await page.content()));
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
void cause;
|
||||
return missing("DOM capture failed");
|
||||
}
|
||||
};
|
||||
@@ -85,7 +87,8 @@ const captureAccessibility = async (input: {
|
||||
try {
|
||||
const text = await page.locator("html").ariaSnapshot();
|
||||
return textArtifact(secrets.redact(text));
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
void cause;
|
||||
return missing("accessibility capture failed");
|
||||
}
|
||||
};
|
||||
@@ -126,7 +129,8 @@ const captureHistory = async (page: Page, secrets: BrowserScenarioSecrets) => {
|
||||
})),
|
||||
};
|
||||
return { state: "captured" as const, value };
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
void cause;
|
||||
return missing("history capture failed");
|
||||
}
|
||||
};
|
||||
@@ -169,7 +173,8 @@ const captureStorage = async (input: {
|
||||
})),
|
||||
};
|
||||
return { state: "captured" as const, value };
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
void cause;
|
||||
return missing("storage capture failed");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -68,9 +68,10 @@ export class PlaywrightScenarioEvents {
|
||||
if (this.ownsContext) return true;
|
||||
try {
|
||||
return this.pages.has(request.frame().page());
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Initial popup navigations can lack a frame. Never guess ownership
|
||||
// from a URL in a shared context; connect captures are attach-limited.
|
||||
void cause;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -314,6 +315,9 @@ export class PlaywrightScenarioEvents {
|
||||
suggested_filename: this.secrets.redact(download.suggestedFilename()),
|
||||
url: this.safeUrl(download.url()),
|
||||
});
|
||||
void download.cancel().catch(() => undefined);
|
||||
void download.cancel().catch((cause: unknown) => {
|
||||
// best-effort cleanup: download cancellation must not reject unhandled.
|
||||
void cause;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,10 @@ export class PlaywrightScenarioSession implements BrowserScenarioSessionPort {
|
||||
.then((lateOpened) =>
|
||||
closePlaywrightScenarioBrowser(lateOpened, options.signal),
|
||||
)
|
||||
.catch(() => undefined);
|
||||
.catch((cause: unknown) => {
|
||||
// best-effort cleanup: late-open cleanup must not mask the boundary failure.
|
||||
void cause;
|
||||
});
|
||||
throw cause;
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -199,7 +199,8 @@ const normalizeSourceMap = (
|
||||
status: "partial",
|
||||
limitation: `Module edges are incomplete: ${modules.incomplete.length} of ${originalSources.filter(({ artifact }) => artifact !== null).length} original sources could not be parsed in full (${modules.incomplete.join(", ")}).`,
|
||||
};
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
void cause;
|
||||
return emptySourceMapItem(
|
||||
request,
|
||||
"invalid",
|
||||
@@ -311,7 +312,9 @@ const approvedUrl = (
|
||||
parsed.password === "" &&
|
||||
allowedOrigins.includes(parsed.origin)
|
||||
);
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Non-URL input is not an approved source-map URL.
|
||||
void cause;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -338,7 +341,9 @@ const emptySourceMapItem = (
|
||||
const sanitizeSource = (value: string): string => {
|
||||
try {
|
||||
return sanitizeBrowserUrl(new URL(value).href).url;
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Non-URL sources are preserved verbatim.
|
||||
void cause;
|
||||
return value;
|
||||
}
|
||||
};
|
||||
@@ -349,7 +354,9 @@ const resolveOriginalSource = (
|
||||
): string | null => {
|
||||
try {
|
||||
return sanitizeSource(new URL(specifier, base).href);
|
||||
} catch {
|
||||
} catch (cause: unknown) {
|
||||
// Unresolvable source specifiers are represented by null.
|
||||
void cause;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user