mirror of
https://github.com/morluto/rea.git
synced 2026-12-07 07:13:04 +08: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)
108 lines
3.5 KiB
TypeScript
108 lines
3.5 KiB
TypeScript
import { WEB_SOURCE_MAP_LIMITS } from "../../domain/sourceMapLimits.js";
|
|
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
|
import {
|
|
AnalysisCapabilityUnavailableError,
|
|
AnalysisInputError,
|
|
AnalysisOutputError,
|
|
} from "../../domain/analysisErrorCore.js";
|
|
import { ArtifactOperationError } from "../../domain/artifactOperationError.js";
|
|
import { err, ok, type Result } from "../../domain/result.js";
|
|
import { javaScriptRuntime } from "../../domain/runtimeVersion.js";
|
|
import type { WebSourceMapReport } from "../../domain/webSourceLocation.js";
|
|
import { sourceMapCodecReplySchema } from "./SourceMapCodecProtocol.js";
|
|
import { errorMessage } from "../../kernel/errorMessage.js";
|
|
|
|
const OPERATION = "trace_web_source_location";
|
|
|
|
/** Interpret the complete codec reply before its command owner finalizes. */
|
|
export const parseSourceMapReply = (
|
|
text: string,
|
|
path: string,
|
|
processMemoryLimitBytes: number | null,
|
|
heapMiB: number = WEB_SOURCE_MAP_LIMITS.codecHeapMiB,
|
|
): Result<WebSourceMapReport, AnalysisError> => {
|
|
let value: unknown;
|
|
try {
|
|
value = JSON.parse(text);
|
|
} catch (cause: unknown) {
|
|
return err(
|
|
new AnalysisOutputError(
|
|
OPERATION,
|
|
`Malformed codec JSON reply: ${errorMessage(cause)}`,
|
|
),
|
|
);
|
|
}
|
|
const reply = sourceMapCodecReplySchema.safeParse(value);
|
|
if (!reply.success)
|
|
return err(
|
|
new AnalysisOutputError(
|
|
OPERATION,
|
|
`Malformed codec reply: ${reply.error.message}`,
|
|
),
|
|
);
|
|
if (reply.data.state === "failure")
|
|
return codecFailure(path, reply.data.reason, reply.data.message);
|
|
const runtimeFailure = codecRuntimeFailure(
|
|
reply.data.report.runtime,
|
|
processMemoryLimitBytes,
|
|
heapMiB,
|
|
);
|
|
return runtimeFailure === undefined
|
|
? ok(reply.data.report)
|
|
: err(new AnalysisOutputError(OPERATION, runtimeFailure));
|
|
};
|
|
|
|
/** Only the launched Node runtime's V8 heap, or Bun's process limit, is admitted. */
|
|
const codecRuntimeFailure = (
|
|
runtime: WebSourceMapReport["runtime"],
|
|
processMemoryLimitBytes: number | null,
|
|
heapMiB: number,
|
|
): string | undefined => {
|
|
if (
|
|
runtime.id !==
|
|
(javaScriptRuntime(process.versions).id === "bun" ? "bun" : "node-v8")
|
|
)
|
|
return `Codec reported runtime ${runtime.id}, not the runtime that launched it.`;
|
|
if (
|
|
runtime.id === "node-v8" &&
|
|
runtime.v8_heap_limit_bytes > (heapMiB + 64) * 1024 * 1024
|
|
)
|
|
return "Codec reported a V8 heap limit exceeding its independent process budget.";
|
|
if (
|
|
runtime.id === "bun" &&
|
|
runtime.process_memory_limit_bytes !== processMemoryLimitBytes
|
|
)
|
|
return "Codec reported a process memory limit other than the one its launcher enforced.";
|
|
return undefined;
|
|
};
|
|
|
|
const codecFailure = (
|
|
path: string,
|
|
reason: "format" | "unsupported" | "limit",
|
|
detail: string,
|
|
): Result<never, AnalysisError> =>
|
|
err(
|
|
reason === "limit"
|
|
? new ArtifactOperationError(
|
|
OPERATION,
|
|
"limit",
|
|
undefined,
|
|
`${path}: ${detail}`,
|
|
{ remediationAction: detail },
|
|
)
|
|
: reason === "unsupported"
|
|
? new AnalysisCapabilityUnavailableError(
|
|
"source-map-decoder",
|
|
OPERATION,
|
|
"unsupported_source_map_profile",
|
|
{ userMessage: `${path}: ${detail}` },
|
|
)
|
|
: new AnalysisInputError(OPERATION, undefined, [
|
|
{
|
|
path: ["source_map", "path"],
|
|
reason: "invalid_format",
|
|
message: `${path}: ${detail}`,
|
|
},
|
|
]),
|
|
);
|