fix: prevent divide-by-zero panic when --align produces no valid chunks#258
Open
dylantirandaz wants to merge 1 commit intoparadigmxyz:mainfrom
Open
fix: prevent divide-by-zero panic when --align produces no valid chunks#258dylantirandaz wants to merge 1 commit intoparadigmxyz:mainfrom
dylantirandaz wants to merge 1 commit intoparadigmxyz:mainfrom
Conversation
…s exist When using --align with a block range that produces no valid aligned chunks (e.g. -b 1:1001 with chunk_size 1000), the alignment rounds start up and end down, resulting in zero partitions. The summary printing then divides by n_chunks (0) to compute percentages, causing a panic. Guard the percentage calculations behind n_chunks > 0 so that empty collection runs print the chunk count without attempting division. Fixes paradigmxyz#150
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.
Motivation
When using
--alignwith a block range that produces no valid aligned chunks, cryo panics with "attempt to divide by zero" in the collection summary (#150).For example,
cryo contracts -b 1:1001 --alignwith the default chunk size of 1000:1.div_ceil(1000) * 1000)1001 / 1000 * 1000)endis not greater thanstart, the chunk is droppedn_chunks = 0n_chunksto compute percentages, causing the panicSolution
Guard the percentage-printing block behind
n_chunks > 0. When there are no chunks, the summary still printstotal chunks: 0but skips the errored/skipped/collected breakdown that requires division.Fixes #150
PR Checklist