Files
reverse-engineering-anything/src/domain/managed/managedReaderFailure.ts
T
morluto ae8fb57ef0 fix(managed): preserve duplicate GUID stream ambiguity (#12217)
* fix(managed): preserve duplicate GUID stream ambiguity

* fix(managed): preserve ambiguous metadata stream declarations (#12226)

Use one stream declaration owner for heap and table diagnostics. Keep user strings and row-layout uncertainty separate from independent PE/CLI observations.

* test(managed): separate heap entries from cache behavior

* fix(managed): preserve duplicate blob heap ambiguity (#12258)

Resolve #Blob in the shared stream layout. Preserve nil references and independent facts without emitting unsupported keys, signatures or hashes.
2026-11-19 03:49:34 -05:00

99 lines
3.3 KiB
TypeScript

import { AnalysisInputError } from "../analysisErrorCore.js";
import type { ManagedParseIssue } from "./managedArtifact.js";
/** Header facts admitted before an unsupported table layout was identified. */
export interface ManagedMetadataHeaderFacts {
readonly version: string;
readonly streamNames: readonly string[];
}
/** Bounded format or applicability failure retained as managed coverage. */
export class ManagedReaderFailure extends Error {
readonly metadataHeader: ManagedMetadataHeaderFacts | null;
constructor(
readonly issue: ManagedParseIssue,
options?: ErrorOptions & {
readonly metadataHeader?: ManagedMetadataHeaderFacts;
},
) {
super(issue.detail, options);
this.metadataHeader = options?.metadataHeader ?? null;
}
}
/** Refuse a heap-dependent row whose shared stream issue is reported by layout inventory. */
export class ManagedHeapAmbiguityFailure extends ManagedReaderFailure {}
/** A resource or unsupported layout leaves metadata unknown, not malformed. */
export const managedMetadataFailureStatus = (
issue: ManagedParseIssue,
): "partial" | "malformed" =>
issue.code === "resource-limit" || issue.code === "unsupported-metadata"
? "partial"
: "malformed";
/** Malformed selected metadata is input failure for every inspection workflow. */
export const managedInspectionInputFailure = (
operation: string,
path: string,
cause: unknown,
inputField: "path" | "leftPath" | "rightPath" = "path",
): AnalysisInputError | undefined =>
cause instanceof ManagedReaderFailure &&
managedMetadataFailureStatus(cause.issue) === "malformed"
? new AnalysisInputError(operation, { cause }, [
{
path: [inputField],
reason: "invalid_format",
message: `Selected artifact ${path}: ${cause.issue.detail}`,
},
])
: undefined;
/** 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) ||
managedMetadataFailureStatus(cause.issue) === "partial"
)
throw cause;
if (!(cause instanceof ManagedHeapAmbiguityFailure))
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(),
];
/**
* Append issue lists one issue at a time. Spreading a list into `push` passes
* one argument per issue, which overflows the stack on large malformed inputs.
*/
export const appendManagedParseIssues = (
issues: ManagedParseIssue[],
...found: readonly (readonly ManagedParseIssue[])[]
): void => {
for (const list of found) for (const issue of list) issues.push(issue);
};