Files
reverse-engineering-anything/src/process/ArtifactCommandPath.ts
T
morluto 5f718ce30e refactor(kernel): give error-message, byte-hex and SHA-256 hex helpers one owner in a new src/kernel layer (#11542)
* 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)
2026-11-16 07:05:30 +08:00

83 lines
2.7 KiB
TypeScript

import { ProviderAdapterError } from "../domain/providerAdapterError.js";
import { realpath } from "node:fs/promises";
import {
artifactSelectedPathErrno,
assertArtifactReadActive,
} from "../resources/index.js";
import type { AnalysisCapturedOutput } from "../domain/analysisErrorBase.js";
import {
AnalysisAccessDeniedError,
AnalysisArtifactChangedError,
} from "../domain/analysisErrorCore.js";
import { errorMessage } from "../kernel/errorMessage.js";
/** The selected launch spelling and the physical file whose bytes are fingerprinted. */
export interface ArtifactCommandPath {
readonly invocationPath: string;
readonly resolvedPath: string;
}
/** Resolve identity without changing the caller's absolute executable selection. */
export const selectArtifactCommandPath = async (
invocationPath: string,
signal?: AbortSignal,
): Promise<ArtifactCommandPath> => {
assertArtifactReadActive(signal);
const resolvedPath = await realpath(invocationPath);
assertArtifactReadActive(signal);
return Object.freeze({ invocationPath, resolvedPath });
};
/** An invocation must still select the admitted physical executable. */
export const assertArtifactCommandPath = async (
selected: ArtifactCommandPath,
operation: string,
options: {
readonly signal?: AbortSignal | undefined;
readonly capturedOutput?: AnalysisCapturedOutput;
} = {},
): Promise<void> => {
assertArtifactReadActive(options.signal);
const changed = (cause?: unknown) =>
new AnalysisArtifactChangedError(
operation,
selected.invocationPath,
"Selected command no longer resolves to its admitted executable.",
{
cause,
...(options.capturedOutput === undefined
? {}
: { capturedOutput: options.capturedOutput }),
},
);
let current: string;
try {
current = await realpath(selected.invocationPath);
} catch (cause: unknown) {
if (artifactSelectedPathErrno(cause) !== undefined) throw changed(cause);
const systemCode =
cause instanceof Error && "code" in cause
? String(cause.code)
: undefined;
const failureOptions = { cause, capturedOutput: options.capturedOutput };
if (systemCode === "EACCES" || systemCode === "EPERM")
throw new AnalysisAccessDeniedError(
operation,
selected.invocationPath,
systemCode,
failureOptions,
);
throw new ProviderAdapterError("rea", operation, {
...failureOptions,
diagnostics: {
path: selected.invocationPath,
reason: errorMessage(cause),
system_code: systemCode ?? null,
},
});
}
if (current !== selected.resolvedPath) throw changed();
assertArtifactReadActive(options.signal);
};