mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
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)
This commit is contained in:
1 parent
ff0176256a
commit
5f718ce30e
291 files changed
+976
-978
No files matched your search
@@ -99,6 +99,7 @@ import {
|
||||
javaScriptWorkerAdmissionSchema,
|
||||
type JavaScriptWorkerMessage,
|
||||
} from "./JavaScriptAnalysisWorkerProtocol.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
|
||||
const OPERATION = "analyze_javascript_application";
|
||||
const PROVIDER = "javascript-static-analysis";
|
||||
@@ -199,7 +200,7 @@ export class JavaScriptAnalysisWorker {
|
||||
"JavaScript worker control frame is unterminated or oversized",
|
||||
);
|
||||
} catch (cause: unknown) {
|
||||
this.#latchOutputFailure(message(cause));
|
||||
this.#latchOutputFailure(errorMessage(cause));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -636,7 +637,7 @@ export class JavaScriptAnalysisWorker {
|
||||
}),
|
||||
)
|
||||
: previous;
|
||||
const error = this.#cleanupError(message(cause), primary);
|
||||
const error = this.#cleanupError(errorMessage(cause), primary);
|
||||
this.#runtime.bindCleanupFailure(error);
|
||||
result = err({
|
||||
javascript,
|
||||
@@ -1454,7 +1455,7 @@ export class JavaScriptAnalysisWorker {
|
||||
)
|
||||
return new AnalysisOutputError(
|
||||
OPERATION,
|
||||
`${path} during ${this.#phase}: ${message(cause)}`,
|
||||
`${path} during ${this.#phase}: ${errorMessage(cause)}`,
|
||||
{ cause, capturedOutput: this.#captured() },
|
||||
);
|
||||
return cause instanceof RuntimeControlUnavailableError
|
||||
@@ -1465,7 +1466,7 @@ export class JavaScriptAnalysisWorker {
|
||||
diagnostics: {
|
||||
source_path: path,
|
||||
phase: this.#phase,
|
||||
message: message(cause),
|
||||
message: errorMessage(cause),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1536,6 +1537,3 @@ export class JavaScriptAnalysisWorker {
|
||||
this.#terminalResponseId = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
const message = (cause: unknown): string =>
|
||||
cause instanceof Error ? cause.message : String(cause);
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
javaScriptWorkerMessageSchema,
|
||||
type JavaScriptWorkerMessage,
|
||||
} from "./JavaScriptAnalysisWorkerProtocol.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
|
||||
/** Trusted composition callback; this provider owns framing and temporary I/O. */
|
||||
export interface JavaScriptSourceWorkerAnalyzer {
|
||||
@@ -239,9 +240,7 @@ const analyzeJob = async (
|
||||
message:
|
||||
cause instanceof AnalysisResourceConstraintError
|
||||
? cause.reason
|
||||
: cause instanceof Error
|
||||
? cause.message
|
||||
: String(cause),
|
||||
: errorMessage(cause),
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
} from "../../filesystem/RegularFile.js";
|
||||
import { RECOVERY_LIMITS, wakaruFixedLimitRecovery } from "./WakaruRelease.js";
|
||||
import { isStrictUtf8 } from "../../domain/strictUtf8.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
|
||||
const OPERATION = "recover_javascript_sources";
|
||||
|
||||
@@ -218,7 +219,7 @@ const snapshotRecoveryInput = async (
|
||||
);
|
||||
throw recoveryInputFailure(
|
||||
"path",
|
||||
`Cannot snapshot UTF-8 JavaScript input ${path}: ${recoveryFailureMessage(cause)}`,
|
||||
`Cannot snapshot UTF-8 JavaScript input ${path}: ${errorMessage(cause)}`,
|
||||
cause,
|
||||
);
|
||||
}
|
||||
@@ -286,7 +287,7 @@ const recoveryInputLayoutPath = async (
|
||||
});
|
||||
throw recoveryInputFailure(
|
||||
"path",
|
||||
`Cannot resolve selected JavaScript input parent ${path}: ${recoveryFailureMessage(cause)}`,
|
||||
`Cannot resolve selected JavaScript input parent ${path}: ${errorMessage(cause)}`,
|
||||
cause,
|
||||
);
|
||||
}
|
||||
@@ -352,7 +353,7 @@ export const snapshotRecoveryInputs = async (
|
||||
} catch (cause: unknown) {
|
||||
throw recoveryInputFailure(
|
||||
"path",
|
||||
`Cannot preserve selected input path in published artifacts: ${path}: ${recoveryFailureMessage(cause)}`,
|
||||
`Cannot preserve selected input path in published artifacts: ${path}: ${errorMessage(cause)}`,
|
||||
cause,
|
||||
);
|
||||
}
|
||||
@@ -479,10 +480,6 @@ export const recoveryInputFailure = (
|
||||
{ path: [field], reason: "invalid_value", message },
|
||||
]);
|
||||
|
||||
/** Convert one caught boundary cause into diagnostic text without masking its type. */
|
||||
export const recoveryFailureMessage = (cause: unknown): string =>
|
||||
cause instanceof Error ? cause.message : String(cause);
|
||||
|
||||
/** Cancellation remains distinct from malformed source or provider output. */
|
||||
export const checkRecoveryCancellation = (signal?: AbortSignal): void => {
|
||||
if (signal?.aborted === true) throw cancelledBy(OPERATION, signal);
|
||||
|
||||
@@ -36,9 +36,9 @@ import {
|
||||
checkRecoveryDeadline,
|
||||
inventoryRecoveryFiles,
|
||||
fingerprintRecoveryFile,
|
||||
recoveryFailureMessage,
|
||||
} from "./RecoveryFiles.js";
|
||||
import { RECOVERY_LIMITS, wakaruFixedLimitRecovery } from "./WakaruRelease.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
|
||||
const OPERATION = "recover_javascript_sources";
|
||||
const WAKARU_REQUIREMENT =
|
||||
@@ -133,7 +133,7 @@ export const resolveWakaruCommand = async (
|
||||
(cause.cleanup !== undefined || cause.reason === "cancelled"))
|
||||
)
|
||||
throw cause;
|
||||
const reason = `Configured Wakaru or util-linux prlimit is unavailable: ${recoveryFailureMessage(cause)}`;
|
||||
const reason = `Configured Wakaru or util-linux prlimit is unavailable: ${errorMessage(cause)}`;
|
||||
throw new AnalysisCapabilityUnavailableError("wakaru", OPERATION, reason, {
|
||||
cause,
|
||||
userMessage: reason,
|
||||
@@ -189,7 +189,7 @@ export const runWakaruCommand = async (context: WakaruCommandContext) => {
|
||||
reason:
|
||||
"Failed to launch configured Wakaru through util-linux prlimit",
|
||||
command: context.command,
|
||||
detail: recoveryFailureMessage(cause),
|
||||
detail: errorMessage(cause),
|
||||
},
|
||||
});
|
||||
primary =
|
||||
|
||||
@@ -37,7 +37,6 @@ import { err, ok, type Result } from "../../domain/result.js";
|
||||
import {
|
||||
checkRecoveryCancellation,
|
||||
checkRecoveryDeadline,
|
||||
recoveryFailureMessage,
|
||||
recoveryInputFailure,
|
||||
snapshotRecoveryInputs,
|
||||
} from "./RecoveryFiles.js";
|
||||
@@ -50,6 +49,7 @@ import type { ProviderProcessSupervisor } from "../../process/ProviderProcess.js
|
||||
import { prepareWakaruExecution } from "./WakaruExecution.js";
|
||||
import { RECOVERY_LIMITS } from "./WakaruRelease.js";
|
||||
import { WakaruReportReadFailure } from "./WakaruReport.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
|
||||
const OPERATION = "recover_javascript_sources";
|
||||
|
||||
@@ -146,7 +146,7 @@ export class WakaruProvider implements JavaScriptRecoveryPort {
|
||||
if (cause instanceof SafeOutputTreeCreationFailure) tree = cause.tree;
|
||||
throw recoveryInputFailure(
|
||||
"output_directory",
|
||||
`Cannot create new recovery directory ${input.output_directory}: ${recoveryFailureMessage(cause)}`,
|
||||
`Cannot create new recovery directory ${input.output_directory}: ${errorMessage(cause)}`,
|
||||
cause,
|
||||
);
|
||||
}
|
||||
@@ -208,7 +208,7 @@ export class WakaruProvider implements JavaScriptRecoveryPort {
|
||||
residuals.push(tree.outputRoot);
|
||||
cleanupFailures.push({
|
||||
resource: tree.outputRoot,
|
||||
reason: recoveryFailureMessage(cause),
|
||||
reason: errorMessage(cause),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -225,7 +225,7 @@ export class WakaruProvider implements JavaScriptRecoveryPort {
|
||||
residuals.push(failedRoot);
|
||||
cleanupFailures.push({
|
||||
resource: failedRoot,
|
||||
reason: recoveryFailureMessage(cause),
|
||||
reason: errorMessage(cause),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -274,7 +274,7 @@ export class WakaruProvider implements JavaScriptRecoveryPort {
|
||||
? failure
|
||||
: new ProviderAdapterError("wakaru", OPERATION, {
|
||||
cause: failure,
|
||||
diagnostics: { reason: recoveryFailureMessage(failure) },
|
||||
diagnostics: { reason: errorMessage(failure) },
|
||||
...(failure instanceof ArtifactReaderFailure &&
|
||||
failure.partialObservation !== undefined
|
||||
? { partialObservation: failure.partialObservation }
|
||||
@@ -299,7 +299,7 @@ export class WakaruProvider implements JavaScriptRecoveryPort {
|
||||
previous_error:
|
||||
failure instanceof WakaruCleanupFailure
|
||||
? (failure.diagnostics?.previous_error ?? null)
|
||||
: recoveryFailureMessage(failure),
|
||||
: errorMessage(failure),
|
||||
cleanup_failures: cleanupFailures,
|
||||
},
|
||||
{
|
||||
@@ -346,7 +346,7 @@ export class WakaruProvider implements JavaScriptRecoveryPort {
|
||||
? failure
|
||||
: new ProviderAdapterError("wakaru", OPERATION, {
|
||||
cause: failure,
|
||||
diagnostics: { reason: recoveryFailureMessage(failure) },
|
||||
diagnostics: { reason: errorMessage(failure) },
|
||||
...(reportFailure === undefined
|
||||
? {}
|
||||
: { capturedOutput: reportFailure.capturedOutput }),
|
||||
@@ -385,7 +385,7 @@ export class WakaruProvider implements JavaScriptRecoveryPort {
|
||||
const error = new ProviderCleanupError(
|
||||
"wakaru",
|
||||
pending.lease.cleanupResources ?? [],
|
||||
{ reason: recoveryFailureMessage(cause) },
|
||||
{ reason: errorMessage(cause) },
|
||||
{ operation: OPERATION, cause },
|
||||
).bindCleanupResourceOwner(pending.lease);
|
||||
pending.lease.bindCleanupError(error);
|
||||
|
||||
@@ -15,13 +15,10 @@ import {
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||
import type { JavaScriptRecoveryResult } from "../../domain/javascript/javascriptRecovery.js";
|
||||
import {
|
||||
isRecoveryFileSizeError,
|
||||
readRecoveryFile,
|
||||
recoveryFailureMessage,
|
||||
} from "./RecoveryFiles.js";
|
||||
import { isRecoveryFileSizeError, readRecoveryFile } from "./RecoveryFiles.js";
|
||||
import { RECOVERY_LIMITS, wakaruFixedLimitRecovery } from "./WakaruRelease.js";
|
||||
import type { runWakaruCommand } from "./WakaruCommand.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
|
||||
const warningSchema = z.looseObject({
|
||||
filename: z.string(),
|
||||
@@ -144,7 +141,7 @@ export const parseWakaruReports = async (context: ReportContext) => {
|
||||
cause,
|
||||
...wakaruReportGuidance(cause),
|
||||
diagnostics: {
|
||||
reason: `Unusable Wakaru recovery report: ${recoveryFailureMessage(cause)}`,
|
||||
reason: `Unusable Wakaru recovery report: ${errorMessage(cause)}`,
|
||||
exit_code: execution.exit_code,
|
||||
signal: execution.signal,
|
||||
stdout: execution.stdout,
|
||||
@@ -283,7 +280,7 @@ export const validateRecoverySourceMap = (
|
||||
} catch (cause: unknown) {
|
||||
throw new AnalysisOutputError(
|
||||
OPERATION,
|
||||
`Invalid emitted source map for ${filename}: ${recoveryFailureMessage(cause)}`,
|
||||
`Invalid emitted source map for ${filename}: ${errorMessage(cause)}`,
|
||||
{ cause },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ import {
|
||||
type SpawnedOwnedProviderProcess,
|
||||
} from "../../process/ProviderProcess.js";
|
||||
import { prepareProcessOwnershipInspection } from "../../process/ProcessOwnershipObservation.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
|
||||
const OPERATION = "trace_web_source_location";
|
||||
const PROVIDER = "source-map-decoder";
|
||||
@@ -143,7 +144,7 @@ export const runSourceMapCommand = async (
|
||||
: { capturedOutput: preparation.capturedOutput }),
|
||||
diagnostics: {
|
||||
map_path: path,
|
||||
error_message: message(cause),
|
||||
error_message: errorMessage(cause),
|
||||
phase: "process_ownership_preparation",
|
||||
},
|
||||
});
|
||||
@@ -236,7 +237,7 @@ class PreparationCleanup implements SourceMapCleanupOwner {
|
||||
} catch (cause: unknown) {
|
||||
return new SourceMapCleanupFailure(cleanup.cleanupResources, {
|
||||
map_path: this.path,
|
||||
cleanup_failures: [message(cause)],
|
||||
cleanup_failures: [errorMessage(cause)],
|
||||
}).bindCleanupDependencies([cleanup], this);
|
||||
}
|
||||
return cleanup.cleanupIncomplete
|
||||
@@ -423,7 +424,10 @@ class OwnedCodec implements SourceMapCleanupOwner {
|
||||
? runtimeControlCapabilityError(PROVIDER, OPERATION, cause)
|
||||
: new ProviderAdapterError(PROVIDER, OPERATION, {
|
||||
cause,
|
||||
diagnostics: { map_path: this.path, error_message: message(cause) },
|
||||
diagnostics: {
|
||||
map_path: this.path,
|
||||
error_message: errorMessage(cause),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -602,7 +606,7 @@ class OwnedCodec implements SourceMapCleanupOwner {
|
||||
await this.#runtime.close();
|
||||
this.#runtime = undefined;
|
||||
} catch (cause: unknown) {
|
||||
failures.push(message(cause));
|
||||
failures.push(errorMessage(cause));
|
||||
}
|
||||
}
|
||||
if (failures.length === 0) {
|
||||
@@ -620,5 +624,3 @@ class OwnedCodec implements SourceMapCleanupOwner {
|
||||
);
|
||||
}
|
||||
}
|
||||
const message = (cause: unknown): string =>
|
||||
cause instanceof Error ? cause.message : String(cause);
|
||||
@@ -10,6 +10,7 @@ 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";
|
||||
|
||||
@@ -27,7 +28,7 @@ export const parseSourceMapReply = (
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
OPERATION,
|
||||
`Malformed codec JSON reply: ${cause instanceof Error ? cause.message : String(cause)}`,
|
||||
`Malformed codec JSON reply: ${errorMessage(cause)}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user