fix: return Result from record constructors instead of panicking (closes #26) - #27
Open
Dani-giron wants to merge 1 commit into
Open
Conversation
reverseame#26) Malformed input no longer panics the whole process; insert() now uses tracing::warn! instead of println!.
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
SimpleNumberRecord::create,SimpleTlshRecord::createandGenericJsonRecord::createbuild records from untrusted strings (e.g. a line read from a dataset file), but usedunwrap()on the parse step. Verified empirically: feeding malformed input to the pre-fix logic panics the process (exit code 101), aborting a whole ingestion run over a single bad entry.Also:
insert()usedprintln!to warn about a duplicate key instead of thetracingcrate already used elsewhere in the codebase.Changes
src/datalayer/error.rs(new):RecordError(InvalidNumber,InvalidTlshHash), each variant carrying the offending input string. ImplementsDisplayandstd::error::Error.src/datalayer/record.rs: all three constructors now returnResult<Self, RecordError>instead of panicking.src/controllers/apotheosis.rs:insert()usestracing::warn!instead ofprintln!.src/bin/test_numbers.rs,test_tlsh.rs: updated to the new signature with.expect(...)(internally generated / pre-validated data, not user input).Scope note:
dump()/load()still returnBox<dyn std::error::Error>rather than a typed error. Left out of this PR since it overlaps with #24 (open, rewritesload()); a unified error type across persistence and record construction is a natural follow-up once that merges.Test plan
tests/record_construction.rs(new, 4 tests): malformed input returnsErrwith the offending input in the message; valid input returnsOk.cargo test,cargo clippy --all-targets --all-features -- -D warnings,rustfmt --checkall pass locally.unwrap()-based logic panics (exit code 101); post-fix returnsErrand the process continues.Closes #26