fix: propagate errors instead of panicking on persistence writes - #63
Merged
Conversation
replace ~155 `.expect("vec write")` calls with `?` across aof.rs and
snapshot.rs. while Vec<u8> writes only fail on OOM, a database should
never panic — it should return an error and let the caller decide.
changed `AofRecord::to_bytes()` return type from `Vec<u8>` to
`Result<Vec<u8>, FormatError>` and updated its caller in `write_record`.
the other two functions (`read_payload_for_tag`, `read_entry`) already
returned Result, so only the `.expect()` calls needed replacing.
kacy
added a commit
that referenced
this pull request
Feb 11, 2026
replace ~155 `.expect("vec write")` calls with `?` across aof.rs and
snapshot.rs. while Vec<u8> writes only fail on OOM, a database should
never panic — it should return an error and let the caller decide.
changed `AofRecord::to_bytes()` return type from `Vec<u8>` to
`Result<Vec<u8>, FormatError>` and updated its caller in `write_record`.
the other two functions (`read_payload_for_tag`, `read_entry`) already
returned Result, so only the `.expect()` calls needed replacing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
replaces ~155
.expect("vec write")calls with?operator across the persistence layer. whileVec<u8>writes only fail on OOM, a database should never panic — it should return an error and let the caller decide.changes:
AofRecord::to_bytes()return type changed fromVec<u8>toResult<Vec<u8>, FormatError>AofWriter::write_record()to propagate with?.expect("vec write")with?inAofReader::read_payload_for_tag()(already returnedResult).expect("vec write")with?inSnapshotReader::read_entry()(already returnedResult)no new error variants needed —
FormatError::Ioalready wrapsio::Errorvia#[from].what was tested
cargo build -p ember-persistence— compiles cleanlycargo test --workspace— all tests passcargo clippy --workspace— no warningsdesign considerations
this is a mechanical, zero-behavioral-change fix.
Vec<u8>writes will continue to succeed in practice — the only difference is that an OOM now produces a cleanFormatError::Ioerror instead of panicking the process.