Give failure codes one table in the store, tested both ways

Open
#768 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
backend

Research direction

Begin at FailureReason::code in crates/domain/src/execution.rs for the canonical spellings, then encode_failure/decode_failure in crates/adapters/store/src/codec.rs where the duplicate literals sit. Copy the #733 pattern: one table read both ways, plus a test walking every variant through a wildcard-free match; reasons carry fields, so supply one sample value each. Extend the existing round-trip tests (repository_exists_round_trips, daemon_stopped_round_trips). Done when both functions read the single table, the exhaustive both-directions store test passes, and no stored text changes.

Written by the indexing model from the issue text.

Description

enhancement priority: low

A failure's stored code is spelled three times, by hand, with nothing that checks they agree for every variant:

  • FailureReason::code in crates/domain/src/execution.rs (the code a hook's LADDERBACK_ERROR and the operation log carry);
  • encode_failure in crates/adapters/store/src/codec.rs, which writes error_code from its own literals rather than from FailureReason::code, except for a refused setting (refusal.code());
  • decode_failure in the same file, which reads error_code back through a third set of literals.

A typo in one of them would write a code that hooks and the log disagree on, or make a stored failure unreadable (StoreError::Corrupt). Only some reasons have a round-trip test (repository_exists_round_trips, daemon_stopped_round_trips, the refusals), so most reasons' codes are asserted nowhere in the store.

#733 did this for operation kinds and warning kinds: each word is written by one spelling, read through a table of the kinds by that same spelling, and the codec's tests walk every variant (from the enum's derived Deserialize) through a match with no wildcard that spells each code as a literal. Failure reasons carry fields, so the same walk needs a list of one sample value per reason rather than the derived variant names.

Change: encode_failure takes the code from FailureReason::code, decode_failure reads it through one table, and a store test walks every reason through an exhaustive match that spells its code as a literal, in both directions. No stored text changes.

Follow-up from #733, which left failure codes out of scope.

Dominant language
Rust
Stars
0
Forks
0
Avg merge
56m
Merged PRs (30d)
349

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nledford/Ladderback

All issues in nledford/Ladderback

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.