mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 13:45:30 +00:00
* refactor(kernel): give error-to-message text one owner in a new src/kernel layer * fix(kernel): keep the regex worker's own error text inside its isolated source * refactor(kernel): exclude copies that run in another realm from the error-message guard by name The regex worker's source string and the page.evaluate fetch in PlaywrightScenarioRequest cannot import errorMessage. The guard now names them, so the counted baseline does not invite a later slice to rewrite them. * refactor(kernel): migrate the long tail of inline error-message copies to errorMessage (#11552) Every provider and adapter folder with six or fewer copies now calls errorMessage from src/kernel. Local helpers whose whole body was the copy (failureMessage, gdbErrorMessage, message, describe, reasonOf, recoveryFailureMessage and four local errorMessage definitions) are removed and their call sites call the owner. Refs #11548 * refactor(kernel): give byte-to-hex formatting one owner in src/kernel (#11560) byteToHex returns the two lowercase hexadecimal digits of one byte. All eight inline copies (native, contracts, domain firmware and desktop, pcap) call it, keeping their own 0x, % or \x notation, and a counted guard with an empty baseline keeps new copies out. Refs #11548 * refactor(kernel): give one-shot SHA-256 hex digests one owner in src/kernel (#11562) sha256Hex digests one in-memory value. A counted guard records the one-shot createHash("sha256").update(x).digest("hex") chains (115 in 101 files) and the first slice migrates domain, contracts and process (35 copies), removing local wrappers (sha256, sha256Text, hash) and the exported sha256Text. Incremental and streamed hashing is not counted. Refs #11548 * refactor(kernel): migrate the application layer's inline error-message copies to errorMessage (#11563) All 69 copies in src/application call errorMessage from src/kernel. Local helpers whose whole body was the copy (errorDetail, causeReason and five local errorMessage definitions) are removed and their call sites call the owner. Refs #11548 * refactor(kernel): migrate the native provider's inline error-message copies to errorMessage (#11567) All 49 copies in src/native call errorMessage from src/kernel. The local errorReason helpers in LldbCallTracer and LldbRetainedObservations, whose whole body was the copy, are removed and their call sites call the owner. Refs #11548 * refactor(kernel): migrate the remaining inline error-message copies to errorMessage (#11569)
79 lines
3.0 KiB
TypeScript
79 lines
3.0 KiB
TypeScript
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
|
import { AnalysisResourceConstraintError } from "../domain/analysisErrorCore.js";
|
|
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
|
import { errorMessage } from "../kernel/errorMessage.js";
|
|
|
|
/** Host storage exhaustion; only these errors establish a storage constraint. */
|
|
const STORAGE_EXHAUSTION_CODES: ReadonlySet<string> = new Set([
|
|
"ENOSPC",
|
|
"EDQUOT",
|
|
]);
|
|
|
|
/** Host or process descriptor exhaustion; the workspace location is usable. */
|
|
const DESCRIPTOR_EXHAUSTION_CODES: ReadonlySet<string> = new Set([
|
|
"EMFILE",
|
|
"ENFILE",
|
|
]);
|
|
|
|
const systemCode = (cause: unknown): string | null =>
|
|
cause instanceof Error && "code" in cause && typeof cause.code === "string"
|
|
? cause.code
|
|
: null;
|
|
|
|
const systemPath = (cause: unknown): string | null =>
|
|
cause instanceof Error && "path" in cause && typeof cause.path === "string"
|
|
? cause.path
|
|
: null;
|
|
|
|
/**
|
|
* Project a filesystem failure while allocating or writing a provider-owned
|
|
* private analysis workspace.
|
|
*
|
|
* Storage exhaustion and file-size refusal are resource constraints. Every
|
|
* other failure, such as a denied, read-only, missing or non-directory
|
|
* temporary parent, is an unusable workspace location: it keeps its system
|
|
* code and failing path instead of being reported as an exceeded allowance.
|
|
*/
|
|
export const privateWorkspaceFailure = (
|
|
providerId: string,
|
|
operation: string,
|
|
cause: unknown,
|
|
workspacePath: string | null,
|
|
): AnalysisError => {
|
|
const code = systemCode(cause);
|
|
const path = systemPath(cause) ?? workspacePath;
|
|
const reason = errorMessage(cause);
|
|
if (code !== null && (STORAGE_EXHAUSTION_CODES.has(code) || code === "EFBIG"))
|
|
return new AnalysisResourceConstraintError(
|
|
operation,
|
|
"file-size",
|
|
`Private analysis workspace failed (${code}): ${reason}`,
|
|
{ workspace_path: workspacePath, path, system_code: code },
|
|
{
|
|
cause,
|
|
// EFBIG is a file-size refusal, so the worker file-size recovery applies.
|
|
...(STORAGE_EXHAUSTION_CODES.has(code)
|
|
? {
|
|
remediationAction:
|
|
"Free disk space or quota on the filesystem holding details.reported_limits.path (the host temporary directory, TMPDIR), then retry.",
|
|
}
|
|
: {}),
|
|
},
|
|
);
|
|
return new ProviderAdapterError(providerId, operation, {
|
|
cause,
|
|
userMessage: `Cannot prepare the private analysis workspace${code === null ? "" : ` (${code})`}: ${reason}`,
|
|
remediationAction:
|
|
code !== null && DESCRIPTOR_EXHAUSTION_CODES.has(code)
|
|
? "Close unused files or raise the open-file limit of the REA process, then retry."
|
|
: "Review details.diagnostics.system_code and details.diagnostics.path. Make the host temporary directory (TMPDIR) an existing directory this user can create files in on a writable filesystem, then retry.",
|
|
diagnostics: {
|
|
stage: "workspace",
|
|
workspace_path: workspacePath,
|
|
path,
|
|
system_code: code,
|
|
reason,
|
|
},
|
|
});
|
|
};
|