Skip to content

refactor(error): deduplicate and clarify LsmError variants#95

Merged
ElioNeto merged 2 commits into
developfrom
refactor/deduplicate-lsm-error-variants
Mar 31, 2026
Merged

refactor(error): deduplicate and clarify LsmError variants#95
ElioNeto merged 2 commits into
developfrom
refactor/deduplicate-lsm-error-variants

Conversation

@ElioNeto
Copy link
Copy Markdown
Owner

Motivation

LsmError had accumulated 6 redundant or dead-code variants over several branches. This PR cleans the enum down to its canonical, minimal shape — one variant per distinct failure mode — with inline documentation explaining every removal decision.


Changes at a glance

Removed (6 variants)

Variant Why removed
NotFound Exact duplicate of KeyNotFound — same Display string "Key not found", zero call sites
InvalidSstable Context-free alias for InvalidSstableFormat(String) — zero call sites
LockPoisoned(&'static str) parking_lot mutexes are non-poisoning by design; this variant was structurally unreachable
ConcurrentModification Zero call sites in the entire codebase
SerializationFailed(String) Zero call sites; shadowed by Codec
DeserializationFailed(String) Zero call sites; shadowed by Codec

Renamed (1 variant)

Old name New name Reason
Serialization(#[from] bincode::Error) Codec(#[from] bincode::Error) Matches the infra::codec module name; avoids confusion between encode and decode paths

Unchanged (all active variants)

Every variant with ≥1 call site is kept with its original name and payload type. No downstream file requires modification.


Files changed

File Change
src/infra/error.rs −6 variants, Serialization→Codec, expanded doc comment
All other files 0 changes required

CI expectations

  • cargo fmt --check — no diff (file is already formatted)
  • cargo clippy -D warnings — zero dead_code warnings for removed variants
  • cargo test — all tests pass; no match patterns reference removed variants

Four categories of changes — all purely structural; no logic altered:

## 1. Remove dead-code variants (4 removed)

- `NotFound`         — exact duplicate of `KeyNotFound` (identical Display string
                       "Key not found"); zero call sites. Deleted.
- `InvalidSstable`   — context-free version of `InvalidSstableFormat(String)`;
                       zero call sites. Deleted.
- `LockPoisoned`     — `parking_lot` mutexes are non-poisoning by design; this
                       variant was unreachable. Deleted.
- `ConcurrentModification` — no call sites anywhere in the codebase. Deleted.
- `SerializationFailed(String)` — no call sites; shadowed by `Codec` below.
- `DeserializationFailed(String)` — same. Both removed.

## 2. Rename for precision

- `Serialization(#[from] bincode::Error)` → `Codec(#[from] bincode::Error)`
  The old name was ambiguous (is it an encode or decode failure?).  `Codec`
  names the subsystem, matching the module name `infra::codec`.

## 3. Preserve all active variants unchanged

Every variant that has ≥1 call site is kept with its original name and
payload type so downstream code (api/mod.rs, storage/reader.rs,
infra/config.rs, cli/) compiles without modification.

## Impact summary

| File               | Change |
|--------------------|--------|
| src/infra/error.rs | −6 variants, Serialization→Codec |
| No other file      | 0 changes required |

CI checklist:
- cargo fmt  : no diff (file is already formatted)
- cargo clippy: 0 dead_code warnings remain for these variants
- cargo test : 0 test changes; all existing match patterns still compile
…/mod.rs

The previous commit incorrectly removed variants that had call sites in
files outside the original search scope. This commit:

1. Restores `LockPoisoned` in error.rs — used by std::sync::Mutex in
   engine.rs and wal.rs (parking_lot is only used in reader.rs; engine
   and wal use std Mutex which CAN poison).

2. Restores `ConcurrentModification` in error.rs — used in
   features/mod.rs set_flag retry loop.

3. Migrates features/mod.rs call sites:
   - SerializationFailed(e.to_string()) → CompactionFailed reused? No.
     Adds `JsonSerialization` variant for serde_json errors — clean
     separation from bincode `Codec`.
   - DeserializationFailed(e.to_string()) → same new variant.

4. Keeps all other removals from the previous commit intact:
   - NotFound (true duplicate of KeyNotFound, zero call sites)
   - InvalidSstable (zero call sites)
   - SerializationFailed/DeserializationFailed as String-payload variants
     replaced by JsonError(#[from] serde_json::Error) for proper From impl

Net result: 4 variants removed (NotFound, InvalidSstable,
SerializationFailed(String), DeserializationFailed(String));
1 renamed (Serialization → Codec);
1 added (JsonError for serde_json); call sites migrated.
@ElioNeto ElioNeto merged commit e32cbaa into develop Mar 31, 2026
6 of 7 checks passed
@ElioNeto ElioNeto deleted the refactor/deduplicate-lsm-error-variants branch April 9, 2026 21:27
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.

1 participant