Skip to content

Replace error-chain with thiserror - #16

Open
bmesuere wants to merge 1 commit into
feature/clap-4from
feature/thiserror
Open

Replace error-chain with thiserror#16
bmesuere wants to merge 1 commit into
feature/clap-4from
feature/thiserror

Conversation

@bmesuere

Copy link
Copy Markdown
Member

Closes #6. error-chain has had no release since 2020.

Stacked on #15 (which is stacked on #14).

All six error_chain! blocks become plain enums deriving thiserror::Error, keeping the same variants, the same messages and the same Error/Result names — so most call sites just lose the ErrorKind indirection.

Two bits of error-chain behaviour that were load bearing

From<String> and From<&str>. error-chain generated these, and several commands lean on them via .map_err(|e| e.to_string())? and .ok_or("...")?. Dropping them silently would have been a compile error in some places and a behaviour change in others, so they are now a Msg variant plus two explicit From impls.

quick_main! printed the cause chain. main now does that by hand, and read_taxa_file keeps its io error as a real #[source] rather than formatting it into the message. Output is byte-identical to before:

Error: Failed opening taxon file.
Caused by: No such file or directory (os error 2)

My first attempt flattened that into one line; keeping the source chain is both closer to the old behaviour and the point of using thiserror.

Verification

Compared against the old binary: identical stderr and exit code for a missing taxon file, a malformed taxon file, and an unknown taxon ID. 38 tests pass, cargo +nightly fmt --check clean, and the pipeline runs end to end through FragGeneScanRs to tryptic peptides.

Two pre-existing things I noticed, not touched here

  • umgap translate -t 99 panics with index out of bounds: the len is 23 but the index is 98 at src/dna/translation.rs:181. The bounds check that would produce UnknownTable sits after the indexing. Both the old and new binaries panic identically, so this is not a regression — but it is a real bug and probably wants its own issue.
  • Clippy is at 100 warnings, up from 96, because the new From impls and enums attract a few more lints. The clippy cleanup is still its own piece of work.

Closes #6. error-chain has not seen a release since 2020.

All six error_chain! blocks become plain enums deriving thiserror::Error,
keeping the same variants, the same messages and the same Error/Result names,
so most call sites only lose the ErrorKind indirection.

Two bits of error-chain behaviour were load bearing and are kept explicitly:

- Error implemented From<String> and From<&str>, which several commands lean
  on through `.map_err(|e| e.to_string())?` and `.ok_or("...")?`. That is now
  a Msg variant plus the two From impls.
- quick_main! printed the error and then walked the cause chain. main does the
  same by hand, and read_taxa_file keeps its io error as a real source rather
  than formatting it into the message, so the output is unchanged:

      Error: Failed opening taxon file.
      Caused by: No such file or directory (os error 2)

Verified against the old binary: identical stderr and exit code for a missing
taxon file, a malformed taxon file and an unknown taxon ID. 38 tests pass and
the pipeline still runs end to end.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 18, 2026 13:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants