Skip to content

fix: return Result from record constructors instead of panicking (closes #26) - #27

Open
Dani-giron wants to merge 1 commit into
reverseame:apotheosis2from
Dani-giron:j1-error-handling-record-construction
Open

fix: return Result from record constructors instead of panicking (closes #26)#27
Dani-giron wants to merge 1 commit into
reverseame:apotheosis2from
Dani-giron:j1-error-handling-record-construction

Conversation

@Dani-giron

Copy link
Copy Markdown

Summary

SimpleNumberRecord::create, SimpleTlshRecord::create and GenericJsonRecord::create build records from untrusted strings (e.g. a line read from a dataset file), but used unwrap() 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() used println! to warn about a duplicate key instead of the tracing crate already used elsewhere in the codebase.

Changes

  • src/datalayer/error.rs (new): RecordError (InvalidNumber, InvalidTlshHash), each variant carrying the offending input string. Implements Display and std::error::Error.
  • src/datalayer/record.rs: all three constructors now return Result<Self, RecordError> instead of panicking.
  • src/controllers/apotheosis.rs: insert() uses tracing::warn! instead of println!.
  • 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 return Box<dyn std::error::Error> rather than a typed error. Left out of this PR since it overlaps with #24 (open, rewrites load()); 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 returns Err with the offending input in the message; valid input returns Ok.
  • cargo test, cargo clippy --all-targets --all-features -- -D warnings, rustfmt --check all pass locally.
  • Manually verified pre-fix behavior: same malformed input against the old unwrap()-based logic panics (exit code 101); post-fix returns Err and the process continues.

Closes #26

 reverseame#26)

Malformed input no longer panics the whole process; insert() now uses tracing::warn! instead of println!.
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