Files
reverse-engineering-anything/src/dotnet/ManagedReaderFailure.ts
T
morluto 0f0d6e4d43 fix(managed): budget decoding before representation expansion
Validation: integrated changes passed formatting, typecheck, lint, resolved module-boundary verification and git diff --check. Tests and real-provider workflows were not run.
2026-10-11 00:03:19 +08:00

46 lines
1.4 KiB
TypeScript

import type { ManagedParseIssue } from "../domain/managed/managedArtifact.js";
/** Bounded format failure retained as caller-visible managed coverage. */
export class ManagedReaderFailure extends Error {
constructor(
readonly issue: ManagedParseIssue,
options?: ErrorOptions,
) {
super(issue.detail, options);
}
}
/** Construct a typed managed parse failure at an exact byte location. */
export const managedFailure = (
code: ManagedParseIssue["code"],
scope: string,
detail: string,
offset: number | null = null,
): ManagedReaderFailure =>
new ManagedReaderFailure({ code, scope, offset, detail });
/** Retain one malformed item's location while allowing independent items to be read. */
export const readManagedValue = <Value>(
operation: () => Value,
issues: ManagedParseIssue[],
): Value | undefined => {
try {
return operation();
} catch (cause: unknown) {
if (
!(cause instanceof ManagedReaderFailure) ||
cause.issue.code === "resource-limit"
)
throw cause;
issues.push(cause.issue);
return undefined;
}
};
/** Preserve issue order while collapsing the same malformed producer fact across facets. */
export const uniqueManagedParseIssues = (
issues: readonly ManagedParseIssue[],
): readonly ManagedParseIssue[] => [
...new Map(issues.map((issue) => [JSON.stringify(issue), issue])).values(),
];