Repository navigation
refactor(parsers): report format failures through one ParseFailure algebra - #10593
Conversation
…gebra 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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[High impact] The PR appears safe to merge; the previous offset finding is fixed and no new actionable issue was found. SummaryThis PR gives parsers one shared failure type and one way to turn format failures into public errors.
No new security issue was identified. Checks were source-based; no tests were run during this review. Whether another PR supersedes this one could not be checked because GitHub authentication was unavailable. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Parser or BinaryReader] --> B[ParseFailureError]
B --> C{Failure kind}
C -->|malformed or truncated| D[AnalysisInputError]
C -->|unsupported| E[AnalysisUnsupportedTargetError]
C -->|limit| F[Producer chooses recovery]
Reviews (3) · Last reviewed commit: "fix(parsers): retain malformed range off..." · Reviewed by Greptile |
Summary
Byte-format parsers each invented their own failure class (
BinaryFormatFailure,V8CodeCacheFormatFailure,WindowsShortcutFormatFailure,ElectronFuseFormatFailure, and about ten more), and each provider re-derived the public category with its owninstanceofladder. This adds one tagged failure algebra in the domain, makesBinaryReaderproduce it, projects it to analysis errors in one place, migrates three per-format classes onto it, and adds counted guards so new raw reads and plain throws in parser folders cannot return.First slice of the parser-kernel workstream (W7). No issue is fixed outright; this is the owner later format migrations build on.
Problem and expected behavior
BinaryReader.range()reported a structure that runs past end of file asmalformed, with no offset or field. Expected:truncated, with the format, the offset and the field it was reading.BinaryFormatFailureladder. Five of them (inspect_kernel_module,inspect_elf_notes,inspect_elf_unwind_ranges,inspect_devicetree,inspect_v8_code_cache) left the selected path out of theinvalid_formatmessage, while the others prefixedSelected artifact <path>:. Expected: one projection with one message form.ElectronFuseFailuresmatchedElectronFuseFormatFailurebut not aBinaryFormatFailurethrown by a shared header reader. Expected: every parser format failure projects the same way.Change and scope
src/domain/parseFailure.ts:ParseFailure = {kind: malformed | truncated | unsupported | limit, format, detail, offset?, field?}.unsupportedcarriesundecodedContentandlimitcarries{name, maximum}.ParseFailureError<Kind>is the one throwable carrier.malformedInputandunsupportedInputare constructors.src/domain/parseFailureAnalysisError.ts: the one projection. Malformed or truncated input becomesAnalysisInputError(invalid_format,Selected artifact <path>: …). Unsupported input becomesAnalysisUnsupportedTargetError, which keepsundecodedContent. Alimitreturnsundefinedbecause only its producer knows the budget to name in the recovery.BinaryReadertakes its native format (elf,pe,macho,cuda-nv-info, or the Go container's format). Out-of-file starts aremalformedand spans that end past EOF aretruncated, both withfieldandoffset.BinaryFormatFailureandBinaryResourceFailureare nowParseFailureErrorsubclasses. They keep their class names, messages and accessors for the 39 existing catch sites, with an alias-first migration. The two positionalundecodedContentarguments became{ undecodedContent: true }.The provider ladders in Go, kernel module, binary hardening, native initializers, ELF notes, ELF unwind ranges, devicetree, native exports, PE (
PeBinaryFailure), V8 code cache, Windows Shortcut and Electron fuses now callparseFailureAnalysisError.Migrated and deleted:
V8CodeCacheFormatFailure,WindowsShortcutFormatFailure,ElectronFuseFormatFailure. The Shortcut header checks now nameHeaderSizeandLinkCLSIDwith their offsets.Three consumers that copied
BinaryFormatFailure.kindinto a narrower union now maptruncatedexplicitly:AndroidJniLibrary,RustBinaryImage, andMachoHardening/AppleDispatchMetadata(kind !== "unsupported"). The compiler found them.Guard 2.5 in
scripts/verify/architecture-guards.mjsuses counted baselines inscripts/verify/architecture-guard-baselines.json. A file may not exceed its count, and--shrink-baselinesonly lowers counts. Baselines measured on this branch:Buffer.read*/DataView.get*numeric reads anywhere insrc/outsideBinaryContainer.ts: 956 in 134 filesthrow new Error|TypeError|RangeError(in parser folders: 211 in 52 filesJSON.parse(in parser folders: 17 in 15 filesThe counted-baseline helper is the same code as in open PR refactor(errors): require a reason for every analysis cancellation #10566 (
checkCounted, same baseline file), so whichever lands second rebases mechanically.docs/development/tool-design.mdgains a paragraph on the owner, the projection and the guard.Intentionally not included (later slices):
RangeErrorchannel:classifyHostRangeErrorand the 17instanceof RangeErrorsites. That is the next PR.MachoSliceSelection, and the other per-format classes (Il2cpp*,PythonPyc*,Model*,RustAuditable*,AppleIps*,SourceMap*,Capture*). The resource classes (V8CodeCacheBudgetFailure,WindowsShortcutResourceFailure,ElectronFuseResourceFailure) are also left: their recovery needs a typed, provider-specific boundary.GpuCodeObjectsProviderstill maps a malformed container toBinaryTargetError(file_format_rejected). That is a different public category, so it needs its own decision.Contribution scope: ordinary refactor within existing boundaries; maintainer scope decision not applicable.
Contract and boundary impact
Semantic owner and earliest changed stage:
src/domain/parseFailure.tsowns the failure facts.BinaryReaderis the earliest producer changed.parseFailureAnalysisErroris the one projection. Twelve provider ladders and three format classes are removed.Contribution scope fit and linked maintainer decision: not applicable (refactor).
CLI and MCP/tool-catalog contract: no schema change. The
invalid_formatmessage for the five providers listed above now carries theSelected artifact <path>:prefix the other providers already used. Public error tags and categories are unchanged.Provider, bridge, target-format, or platform compatibility: none.
Evidence, artifact, provenance, or reconstruction contract: none.
Target selection, authority, upstream behavior, and cleanup details: not applicable.
Generated metadata, package, or installation impact: none.
Read existing files or captured data.
Evidence and regression coverage
src/native/metadata/BinaryContainer.test.ts: an ELFPT_LOADrunning past EOF fails as{kind: "truncated", format: "elf", offset: 0, field: "ELF load segment"}, while the same segment inside the file is admitted.src/domain/parseFailureAnalysisError.test.ts: malformed and truncated project toinvalid_formatwith the path; unsupported projects to an unsupported target that keepsundecodedContent; a limit or an unrelatedRangeErroris left to the producer.V8CodeCacheParser.test.tsandWindowsShortcutParser.test.tsnow assert the algebra's facts instead of the deleted class names.src/native/metadata/BinaryContainer.tsrestored fromorigin/main, the new truncation test fails (1 failed, 23 passed). With this change it passes.Validation performed
node scripts/run-typescript.mjs --noEmit— passednpm run check:fast— passed (typecheck + lint)npx knip --cache— no findingsnode scripts/verify/architecture-guards.mjs— passed across 2786 source filesnpm run test:local --48 test files undersrc/native/{elf,hardening,initializers,exports,pe,windows,metadata,android},src/native/AppleDispatchMetadata*,src/firmware/devicetree,src/go,src/v8,src/electron,src/gpu,src/rust— 48 files passed, 1327 tests passed, 2 skippednpm run test:focused --48 CLI acceptance, MCP boundary, provider finalization and application-service test files for the touched providers (for exampletests/acceptance/kernelModuleCli.test.ts,tests/boundary/mcp/elfNotesMcp.test.ts,tests/boundary/go/goBinaryProvider.test.ts,tests/process-global/electronFuseCleanup.test.ts) — 48 files passed, 851 tests passednpm run test:local -- src/domain/parseFailureAnalysisError.test.ts— 4 passednpx oxfmton changed files — cleanCompatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.