mirror of
https://github.com/morluto/rea.git
synced 2026-11-17 04:04:25 +00:00
* refactor(parsers): report format failures through one ParseFailure algebra Add ParseFailure (malformed, truncated, unsupported, limit, with format, offset and field) and its one carrier, ParseFailureError, in the domain. BinaryReader now names truncation and the field it read, and its native format and resource failures are ParseFailureError subclasses. Providers projected a format failure with their own instanceof ladder, and some dropped the selected path from the invalid_format message. parseFailureAnalysisError now owns that projection for the native, Go, devicetree, V8, Windows Shortcut and Electron fuse providers. The V8 code cache, Windows Shortcut and Electron fuse format classes are removed in favour of the algebra. The architecture guard counts raw Buffer and DataView reads, plain Error throws in parser folders and plain JSON.parse of parser input against baselines that can only shrink. * fix(parsers): retain malformed range offsets
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import {
|
|
AnalysisInputError,
|
|
AnalysisUnsupportedTargetError,
|
|
} from "./analysisErrorCore.js";
|
|
import { ParseFailureError } from "./parseFailure.js";
|
|
|
|
/**
|
|
* The public refusal for a parser's format failure on the selected artifact.
|
|
*
|
|
* Malformed and truncated bytes are an invalid `path`; unsupported bytes are
|
|
* an unsupported target. A `limit` and any other cause return `undefined`:
|
|
* a limit's recovery names a budget only its producer knows.
|
|
*/
|
|
export const parseFailureAnalysisError = (
|
|
operation: string,
|
|
path: string,
|
|
cause: unknown,
|
|
): AnalysisInputError | AnalysisUnsupportedTargetError | undefined => {
|
|
if (!(cause instanceof ParseFailureError)) return undefined;
|
|
const { failure } = cause;
|
|
switch (failure.kind) {
|
|
case "limit":
|
|
return undefined;
|
|
case "unsupported":
|
|
return new AnalysisUnsupportedTargetError(
|
|
operation,
|
|
path,
|
|
failure.detail,
|
|
{ cause, undecodedContent: failure.undecodedContent },
|
|
);
|
|
case "malformed":
|
|
case "truncated":
|
|
return new AnalysisInputError(operation, { cause }, [
|
|
{
|
|
path: ["path"],
|
|
reason: "invalid_format",
|
|
message: `Selected artifact ${path}: ${failure.detail}`,
|
|
},
|
|
]);
|
|
}
|
|
};
|