mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +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
@@ -1,18 +1,29 @@
|
||||
import type { PYTHON_PYC_LIMIT_MAXIMA } from "../domain/python/pythonPyc.js";
|
||||
import { decodeLimit } from "../domain/parseFailure.js";
|
||||
import type { PythonPycLimits } from "../domain/python/pythonPyc.js";
|
||||
|
||||
/** The ParseFailure format of a standalone CPython pyc. */
|
||||
export const PYTHON_PYC_FORMAT = "python-pyc";
|
||||
|
||||
/** Resource boundary exceeded while walking marshal objects. */
|
||||
export class PythonPycResourceFailure extends Error {
|
||||
constructor(
|
||||
readonly boundary: "objects" | "depth" | "string",
|
||||
readonly reported_limits: Readonly<
|
||||
Partial<Record<keyof typeof PYTHON_PYC_LIMIT_MAXIMA, number>>
|
||||
>,
|
||||
message: string,
|
||||
) {
|
||||
super(message);
|
||||
this.name = "PythonPycResourceFailure";
|
||||
}
|
||||
}
|
||||
/** Caller controls that determine each parser-owned allowance. */
|
||||
const LIMIT_CONTROLS = {
|
||||
max_objects: ["max_objects"],
|
||||
max_depth: ["max_depth"],
|
||||
max_string_bytes: ["max_string_bytes"],
|
||||
reported_string_bytes: ["max_file_bytes"],
|
||||
reported_rows: ["max_objects"],
|
||||
nested_code_steps: ["max_objects", "max_depth"],
|
||||
nested_code_references: ["max_objects", "max_depth"],
|
||||
marshal_key_steps: ["max_objects"],
|
||||
marshal_key_bytes: ["max_file_bytes"],
|
||||
} as const satisfies Record<string, readonly (keyof PythonPycLimits)[]>;
|
||||
|
||||
export const pythonPycLimit = (
|
||||
name: keyof typeof LIMIT_CONTROLS,
|
||||
maximum: number,
|
||||
detail: string,
|
||||
) => decodeLimit(PYTHON_PYC_FORMAT, detail, { name, maximum });
|
||||
|
||||
export const pythonPycLimitControls = (
|
||||
boundary: string,
|
||||
): readonly (keyof PythonPycLimits)[] =>
|
||||
Object.entries(LIMIT_CONTROLS).find(([name]) => name === boundary)?.[1] ?? [];
|
||||
Reference in new issue
Block a user