mirror of
https://github.com/morluto/rea.git
synced 2026-11-14 18:52:48 +00:00
refactor: remove redundant seams and preserve cleanup ownership (#10375)
* refactor: remove redundant seams and preserve cleanup ownership * fix: validate PE resource extents before budget checks
This commit is contained in:
1 parent
4b26f38d6f
commit
cdc4541ef7
369 files changed
+3847
-3662
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { escapeJsonPointerToken } from "../../domain/jsonPointer.js";
|
||||
import type { AnalysisSettingsReader } from "../../domain/analysisSettings.js";
|
||||
import {
|
||||
ASAR_HEADER_ADMISSION_SETTING,
|
||||
@@ -145,7 +146,8 @@ export const analyzeJavaScriptApplicationValidated = async (
|
||||
});
|
||||
assertJavaScriptAnalysisActive(options.signal);
|
||||
return ok(evidence);
|
||||
} catch (cause: unknown) {
|
||||
} catch (caught: unknown) {
|
||||
let cause = caught;
|
||||
if (
|
||||
cause instanceof ArtifactReaderFailure &&
|
||||
cause.reason === "cancelled" &&
|
||||
@@ -246,13 +248,10 @@ const describeResultSchemaFailure = (cause: z.ZodError): string => {
|
||||
const pointer =
|
||||
path.length === 0
|
||||
? "/"
|
||||
: `/${path.map((part) => escapePointerPart(String(part))).join("/")}`;
|
||||
: `/${path.map((part) => escapeJsonPointerToken(String(part))).join("/")}`;
|
||||
return `Result schema rejected ${String(cause.issues.length)} ${cause.issues.length === 1 ? "issue" : "issues"} at ${pointer} (${issue.code})`;
|
||||
};
|
||||
|
||||
const escapePointerPart = (part: string): string =>
|
||||
part.replaceAll("~", "~0").replaceAll("/", "~1");
|
||||
|
||||
const FILESYSTEM_ERROR_CODES = new Set([
|
||||
"ENOENT",
|
||||
"EACCES",
|
||||
|
||||
@@ -214,8 +214,11 @@ export const reconstructJavaScriptArtifact = async (
|
||||
).length,
|
||||
{ scope },
|
||||
);
|
||||
let outcome;
|
||||
let cleanupFailure: AnalysisError | undefined;
|
||||
let outcome!: Awaited<
|
||||
ReturnType<typeof analyzeAndAdoptJavaScriptArtifactFiles>
|
||||
>;
|
||||
let analysisFailure: { readonly cause: unknown } | undefined;
|
||||
let cleanupAttempt: Awaited<ReturnType<ArtifactResourceScope["release"]>>;
|
||||
try {
|
||||
outcome = await analyzeAndAdoptJavaScriptArtifactFiles(
|
||||
files,
|
||||
@@ -250,18 +253,28 @@ export const reconstructJavaScriptArtifact = async (
|
||||
preloads.paths,
|
||||
preloads.limitations,
|
||||
);
|
||||
} catch (cause: unknown) {
|
||||
analysisFailure = { cause };
|
||||
} finally {
|
||||
try {
|
||||
const cleanup = await scope.release({
|
||||
kind: "javascript-source-analysis",
|
||||
analysis: worker,
|
||||
resource: `JavaScript source analyzer for ${path}`,
|
||||
});
|
||||
if (cleanup.kind === "failed") throw cleanup.cause;
|
||||
} catch (cause: unknown) {
|
||||
if (!(cause instanceof AnalysisError)) throw cause;
|
||||
cleanupFailure = cause;
|
||||
}
|
||||
cleanupAttempt = await scope.release({
|
||||
kind: "javascript-source-analysis",
|
||||
analysis: worker,
|
||||
resource: `JavaScript source analyzer for ${path}`,
|
||||
});
|
||||
}
|
||||
if (analysisFailure !== undefined) {
|
||||
if (cleanupAttempt.kind === "failed")
|
||||
throw scope.cleanupFailure(
|
||||
{ kind: "failed", cause: analysisFailure.cause },
|
||||
[cleanupAttempt],
|
||||
);
|
||||
throw analysisFailure.cause;
|
||||
}
|
||||
let cleanupFailure: AnalysisError | undefined;
|
||||
if (cleanupAttempt.kind === "failed") {
|
||||
if (!(cleanupAttempt.cause instanceof AnalysisError))
|
||||
throw cleanupAttempt.cause;
|
||||
cleanupFailure = cleanupAttempt.cause;
|
||||
}
|
||||
const analysis = outcome.analysis;
|
||||
let interruption = outcome.interruption;
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { BrowserObservationError } from "../../domain/browserObservationError.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisOutputError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { AnalysisCancelledError } from "../../domain/analysisErrorCore.js";
|
||||
import { err, ok } from "../../domain/result.js";
|
||||
import { parseEvidence } from "../../domain/evidence.js";
|
||||
import type { JavaScriptRuntimeTargetList } from "../../domain/javascript/javascriptRuntimeObservation.js";
|
||||
|
||||
Reference in new issue
Block a user