mirror of
https://github.com/morluto/rea.git
synced 2026-11-24 13:18:39 +00:00
refactor(python): report pyc parser limits from LimitRef (#12213)
This commit is contained in:
1 parent
954a2511b7
commit
84551888ec
7 files changed
+182
-118
No files matched your search
@@ -19,33 +19,35 @@ import { AnalysisResourceConstraintError } from "../domain/analysisErrorCore.js"
|
||||
import {
|
||||
PYTHON_PYC_LIMIT_MAXIMA,
|
||||
type InspectPythonPycInput,
|
||||
type PythonPycLimits,
|
||||
} from "../domain/python/pythonPyc.js";
|
||||
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
||||
import { err, ok } from "../domain/result.js";
|
||||
import { PythonPycResourceFailure } from "./PythonPyc.errors.js";
|
||||
import { parseFailureAnalysisError } from "../domain/parseFailureAnalysisError.js";
|
||||
import {
|
||||
PYTHON_PYC_FORMAT,
|
||||
pythonPycLimitControls,
|
||||
} from "./PythonPyc.errors.js";
|
||||
import {
|
||||
isParseLimit,
|
||||
parseFailureAnalysisError,
|
||||
parseLimitConstraint,
|
||||
} from "../domain/parseFailureAnalysisError.js";
|
||||
import { parsePythonPyc } from "./PythonPycParser.js";
|
||||
import { errorMessage } from "../kernel/errorMessage.js";
|
||||
|
||||
const OPERATION = "inspect_python_pyc";
|
||||
|
||||
const parserLimitRecovery = (
|
||||
limits: PythonPycResourceFailure["reported_limits"],
|
||||
input: InspectPythonPycInput,
|
||||
fields: readonly (keyof PythonPycLimits)[],
|
||||
) => {
|
||||
const actions = (
|
||||
Object.keys(
|
||||
PYTHON_PYC_LIMIT_MAXIMA,
|
||||
) as (keyof typeof PYTHON_PYC_LIMIT_MAXIMA)[]
|
||||
).flatMap((field) => {
|
||||
const selected = limits[field];
|
||||
if (selected === undefined) return [];
|
||||
const actions = fields.map((field) => {
|
||||
const selected = input[field];
|
||||
const maximum = PYTHON_PYC_LIMIT_MAXIMA[field];
|
||||
const option = `--${field.replaceAll("_", "-")}`;
|
||||
return [
|
||||
selected < maximum
|
||||
? `Raise ${field} (${option}) above ${selected}, up to ${maximum}, on the next call.`
|
||||
: `${field} (${option}) is at this operation's maximum of ${maximum}; select a complete artifact within that bound.`,
|
||||
];
|
||||
return selected < maximum
|
||||
? `Raise ${field} (${option}) above ${selected}, up to ${maximum}, on the next call.`
|
||||
: `${field} (${option}) is at this operation's maximum of ${maximum}; select a complete artifact within that bound.`;
|
||||
});
|
||||
return {
|
||||
retryable: false as const,
|
||||
@@ -66,14 +68,15 @@ const failureForPrimary = (
|
||||
input.path,
|
||||
);
|
||||
if (identityFailure !== undefined) return identityFailure;
|
||||
if (cause instanceof PythonPycResourceFailure)
|
||||
return new AnalysisResourceConstraintError(
|
||||
if (isParseLimit(cause, PYTHON_PYC_FORMAT)) {
|
||||
const { name } = cause.failure.limit;
|
||||
return parseLimitConstraint(
|
||||
OPERATION,
|
||||
cause.boundary === "depth" ? "capacity" : "memory",
|
||||
cause.message,
|
||||
cause.reported_limits,
|
||||
{ cause, ...parserLimitRecovery(cause.reported_limits) },
|
||||
name === "max_depth" ? "capacity" : "memory",
|
||||
cause,
|
||||
parserLimitRecovery(input, pythonPycLimitControls(name)),
|
||||
);
|
||||
}
|
||||
const formatFailure = parseFailureAnalysisError(OPERATION, input.path, cause);
|
||||
if (formatFailure !== undefined) return formatFailure;
|
||||
if (
|
||||
@@ -88,7 +91,7 @@ const failureForPrimary = (
|
||||
{ max_file_bytes: input.max_file_bytes },
|
||||
{
|
||||
cause,
|
||||
...parserLimitRecovery({ max_file_bytes: input.max_file_bytes }),
|
||||
...parserLimitRecovery(input, ["max_file_bytes"]),
|
||||
},
|
||||
);
|
||||
if (cause.reason === "path" || cause.reason === "format")
|
||||
|
||||
Reference in new issue
Block a user