mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 21:53:51 +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)
136 lines
4.5 KiB
TypeScript
136 lines
4.5 KiB
TypeScript
import { cancelledBy, carriedReason } from "../../domain/analysisErrorCore.js";
|
|
import { AnalysisError } from "../../domain/analysisErrorBase.js";
|
|
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
|
import { ProviderCleanupError } from "../../domain/providerCleanupError.js";
|
|
import { AnalysisCleanupRelease } from "../../domain/analysisCleanupRelease.js";
|
|
import type { TaskFileView } from "../../domain/desktop/appTaskChecks.js";
|
|
import { OwnedCommandFailure } from "../../process/OwnedCommand.js";
|
|
import { RetainedCommandCleanup } from "../../process/RetainedCommandCleanup.js";
|
|
import {
|
|
processWorkerCleanup,
|
|
type RetainedWorkerCleanup,
|
|
} from "../../process/OwnedWorkerRuntime.js";
|
|
import { DESKTOP_PROVIDER } from "./DesktopCaptureRefusals.js";
|
|
import { errorMessage } from "../../kernel/errorMessage.js";
|
|
|
|
const OPERATION = "export_desktop_application";
|
|
|
|
export interface ReaderFacts {
|
|
readonly views: ReadonlyMap<string, TaskFileView>;
|
|
readonly absent: readonly string[];
|
|
}
|
|
|
|
const primaryFailure = (cause: unknown): AnalysisError | undefined => {
|
|
if (cause instanceof AnalysisError) return cause;
|
|
if (cause === undefined) return undefined;
|
|
return cause instanceof OwnedCommandFailure && cause.reason === "cancelled"
|
|
? cancelledBy(OPERATION, carriedReason(cause.cancellation?.reason))
|
|
: new ProviderAdapterError(DESKTOP_PROVIDER.id, OPERATION, {
|
|
cause,
|
|
userMessage: `The task reader could not complete: ${errorMessage(cause)}`,
|
|
});
|
|
};
|
|
|
|
const readerDiagnostics = ({ views, absent }: ReaderFacts) => ({
|
|
...(views.size === 0
|
|
? {}
|
|
: {
|
|
completed_reader_views: Object.fromEntries(
|
|
[...views].map(([id, view]) => [
|
|
id,
|
|
{
|
|
format: view.format,
|
|
view: view.view,
|
|
...(view.compression === undefined
|
|
? {}
|
|
: { compression: view.compression }),
|
|
...(view.error === undefined ? {} : { error: view.error }),
|
|
},
|
|
]),
|
|
),
|
|
}),
|
|
...(absent.length === 0 ? {} : { completed_reader_absent: [...absent] }),
|
|
});
|
|
|
|
/** Preserve completed readers when a later reader fails or is cancelled. */
|
|
export const readerFailure = (
|
|
cause: unknown,
|
|
facts: ReaderFacts,
|
|
): AnalysisError =>
|
|
(
|
|
primaryFailure(cause) ??
|
|
new ProviderAdapterError(DESKTOP_PROVIDER.id, OPERATION, { cause })
|
|
).retainDiagnostics(readerDiagnostics(facts));
|
|
|
|
/** Own an unconfirmed reader process and its working folder across requests. */
|
|
class ReaderCleanup implements RetainedWorkerCleanup {
|
|
#retry: Promise<void> | undefined;
|
|
readonly #released = new AnalysisCleanupRelease();
|
|
constructor(
|
|
readonly owner: RetainedCommandCleanup,
|
|
readonly failure: ProviderCleanupError,
|
|
) {
|
|
this.#released.bind(failure.bindCleanupResourceOwner(owner));
|
|
}
|
|
|
|
retryRetainedCleanup(): Promise<void> {
|
|
if (this.#retry !== undefined) return this.#retry;
|
|
const attempt = this.#release();
|
|
this.#retry = attempt;
|
|
void attempt
|
|
.finally(() => {
|
|
this.#retry = undefined;
|
|
})
|
|
.catch(() => {});
|
|
return attempt;
|
|
}
|
|
|
|
async #release(): Promise<void> {
|
|
try {
|
|
await this.owner.close();
|
|
processWorkerCleanup.delete(this);
|
|
this.#released.confirm();
|
|
} catch (cause: unknown) {
|
|
this.failure.retainDiagnostics({
|
|
retry_failure: errorMessage(cause),
|
|
});
|
|
throw this.failure;
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Retain the physical owner before projecting an interrupted reader result. */
|
|
export const retainReaderCleanup = (
|
|
folder: string,
|
|
cause: unknown,
|
|
facts: ReaderFacts,
|
|
folderFailure?: { readonly cause: unknown },
|
|
): ProviderCleanupError | undefined => {
|
|
const owner = new RetainedCommandCleanup(folder, cause);
|
|
if (!owner.hasPendingCommandResources && folderFailure === undefined)
|
|
return undefined;
|
|
const original = primaryFailure(cause);
|
|
const resources = owner.cleanupResources;
|
|
const problem =
|
|
folderFailure?.cause ??
|
|
(cause instanceof OwnedCommandFailure ? cause.cleanupFailure : undefined) ??
|
|
cause;
|
|
const failure = new ProviderCleanupError(
|
|
DESKTOP_PROVIDER.id,
|
|
resources,
|
|
{
|
|
reason: errorMessage(problem),
|
|
...readerDiagnostics(facts),
|
|
},
|
|
{
|
|
operation: OPERATION,
|
|
cause,
|
|
...(original === undefined ? {} : { cleanupPrimary: original }),
|
|
remediationAction:
|
|
"Retry cleanup in this REA process before starting another reader; if it exits first, inspect the reported local resources.",
|
|
},
|
|
);
|
|
processWorkerCleanup.add(new ReaderCleanup(owner, failure));
|
|
return failure;
|
|
};
|