Skip to content
This repository was archived by the owner on May 21, 2026. It is now read-only.

fix: improve error mapping in readers/writers and benchmark#32

Merged
N283T merged 1 commit into
mainfrom
fix/error-handling-improvements
Apr 26, 2026
Merged

fix: improve error mapping in readers/writers and benchmark#32
N283T merged 1 commit into
mainfrom
fix/error-handling-improvements

Conversation

@N283T

@N283T N283T commented Apr 26, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #25, #26, #27, #28.

Replace silent / overly-coarse error catches with structured error mapping. Adds new error variants so callers can actually triage failures.

Library changes

  • `XtcError` / `TrrError` gain: `AccessDenied`, `IsDir`, `NoSpaceLeft`, `IoError`. `XtcError` also gains `InvalidHeader`.
  • New `mapOpenError()` helper in each module unifies the open/create error mapping path.
  • `Reader.open` uses `allow_directory = false` so opening a directory fails fast with `IsDir` at open time. (#25)
  • `Reader.open` previously collapsed every open error into `FileNotFound`; now it distinguishes the important cases. (#25)
  • `TrrWriter.open` append: `temp_reader.readHeader() catch return ReadError` → `try`, so `InvalidMagic` / `InvalidHeader` survive. (#26)
  • `XtcWriter.open` append: distinguish truncated header (`InvalidHeader`) from real `ReadFailed` (`ReadError`). (#26)
  • Writer `createFile` / `openFile` now distinguish `AccessDenied`, `IsDir`, `NoSpaceLeft` instead of collapsing into `WriteError`. (#27)
  • `XtcReader.open`: non-positive natoms in the header is now `InvalidAtomCount` (not `ReadError`).

Benchmark changes

  • `loadReference`: log non-FileNotFound errors and JSON parse errors instead of silently returning null. (#28)
  • `benchmarkXtc` / `benchmarkTrr`: log stat and open failures with the failing path and error name. `FileNotFound` still stays silent (intentional: lets users skip files that are not on this machine).

Test plan

  • `zig build test` — 34/34 pass (29 + 5 new)
  • `zig build validate` — 36/36 pass
  • `zig build cross-format` — 37/37 pass
  • CI green on Linux + macOS (matrix from ci: add macos-latest to CI matrix #31)

Compatibility

This is technically additive (new error variants), but exhaustive switches over `XtcError` / `TrrError` will need new arms. Minor bump recommended at next release.

Closes #25, #26, #27, #28.

Library:
- XtcError / TrrError gain AccessDenied, IsDir, NoSpaceLeft, IoError;
  XtcError also gains InvalidHeader.
- mapOpenError() helper unifies open/create error mapping. Previously
  every Reader.open failure collapsed into FileNotFound, every
  Writer.open failure into WriteError -- both now distinguish the
  important cases.
- Reader.open uses allow_directory=false so opening a directory
  fails fast with IsDir at open time instead of later with
  generic ReadError on the first read.
- TrrWriter.open append: replace mapping `readHeader catch ReadError`
  with `try`, so InvalidMagic / InvalidHeader survive.
- XtcWriter.open append: distinguish truncated header
  (InvalidHeader) from real ReadFailed (ReadError).
- XtcReader.open: non-positive natoms now reported as
  InvalidAtomCount instead of ReadError.

Tests:
- New IsDir tests for both Readers and Writers (XTC + TRR).

Benchmark:
- loadReference: log non-FileNotFound errors and JSON parse
  errors instead of silently returning null.
- benchmarkXtc / benchmarkTrr: log stat and open failures
  with the failing path and error name; FileNotFound stays silent.
@N283T N283T merged commit f265dc2 into main Apr 26, 2026
1 check passed
@N283T N283T deleted the fix/error-handling-improvements branch April 26, 2026 08:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Reader.open swallows all errors as FileNotFound

1 participant