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)
45 lines
1.7 KiB
TypeScript
45 lines
1.7 KiB
TypeScript
import { z } from "zod";
|
|
import { errorMessage } from "../kernel/errorMessage.js";
|
|
|
|
/**
|
|
* What `describeValidationFailure` states in prose, as facts a caller can act
|
|
* on without reading the description.
|
|
*/
|
|
export interface ValidationIssueFacts {
|
|
/** The first issue's location. */
|
|
readonly path: readonly (string | number)[];
|
|
/** The constraint a custom refinement named on the first issue. */
|
|
readonly constraint: string | undefined;
|
|
/** Further issues the description summarizes as "(N more issues)". */
|
|
readonly remainingIssueCount: number;
|
|
}
|
|
|
|
/** The first schema issue's facts, when the cause is a schema failure. */
|
|
export const firstValidationIssue = (
|
|
cause: unknown,
|
|
): ValidationIssueFacts | undefined => {
|
|
if (!(cause instanceof z.ZodError)) return undefined;
|
|
const [first, ...rest] = cause.issues;
|
|
if (first === undefined) return undefined;
|
|
const constraint: unknown =
|
|
first.code === "custom" ? first.params?.["constraint"] : undefined;
|
|
return {
|
|
path: first.path.map((key) =>
|
|
typeof key === "number" ? key : String(key),
|
|
),
|
|
constraint: typeof constraint === "string" ? constraint : undefined,
|
|
remainingIssueCount: rest.length,
|
|
};
|
|
};
|
|
|
|
/** Locate the first schema issue, or keep a thrown constraint message. */
|
|
export const describeValidationFailure = (cause: unknown): string => {
|
|
if (!(cause instanceof z.ZodError)) return errorMessage(cause);
|
|
const [first, ...rest] = cause.issues;
|
|
const location =
|
|
first === undefined || first.path.length === 0
|
|
? "the document root"
|
|
: first.path.map(String).join(".");
|
|
return `at ${location}: ${first?.message ?? "invalid value"}${rest.length === 0 ? "" : ` (${String(rest.length)} more issues)`}`;
|
|
};
|