Skip to content

Replace panic in RollHash::set_k with an error - #86

Merged
johnlees merged 4 commits into
bacpop:mainfrom
tmaklin:no-panic-from-rollhash-set_k
Aug 20, 2026
Merged

Replace panic in RollHash::set_k with an error#86
johnlees merged 4 commits into
bacpop:mainfrom
tmaklin:no-panic-from-rollhash-set_k

Conversation

@tmaklin

@tmaklin tmaklin commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Hi, another small PR to facilitate library usage. Hope it's OK.

The current implementations of RollHash will panic for invalid input data when set_k is called. I think it'd be better to return an error so these inputs can be skipped/fixed/inspected etc. so that the panic doesn't crash the entire program if sketchlib is used as a library.

I've implemented this and propagated the errors up to sketch_files, which just unwraps them. Same for sketch_files_inverted. This does break compatibility with previous versions again, though, if the affected functions are used somewhere else.

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.67347% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.01%. Comparing base (af38422) to head (611da60).

Files with missing lines Patch % Lines
src/sketch/mod.rs 87.09% 4 Missing ⚠️
src/hashing/aahash_iterator.rs 50.00% 2 Missing ⚠️
src/hashing/nthash_iterator.rs 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
- Coverage   90.08%   90.01%   -0.07%     
==========================================
  Files          17       17              
  Lines        3974     3977       +3     
==========================================
  Hits         3580     3580              
- Misses        394      397       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@johnlees

Copy link
Copy Markdown
Member

Thanks Tommi, looks good!

Could you bump the patch version?

@tmaklin

tmaklin commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

done!

@johnlees
johnlees merged commit 3f9eb13 into bacpop:main Aug 20, 2026
2 of 4 checks passed
@mtrsl

mtrsl commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

It probably doesn't matter, but the general advice is to define your own error types for library functions to return (manually or using the zero-overhead & transparent library thiserror to make that easier), and use anyhow only in application code to "consume" errors.

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.

3 participants