Skip to content

fix: prevent divide-by-zero panic when --align produces no valid chunks#258

Open
dylantirandaz wants to merge 1 commit intoparadigmxyz:mainfrom
dylantirandaz:fix/align-divide-by-zero
Open

fix: prevent divide-by-zero panic when --align produces no valid chunks#258
dylantirandaz wants to merge 1 commit intoparadigmxyz:mainfrom
dylantirandaz:fix/align-divide-by-zero

Conversation

@dylantirandaz
Copy link
Copy Markdown

Motivation

When using --align with 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 --align with the default chunk size of 1000:

  • Alignment rounds the start up to 1000 (1.div_ceil(1000) * 1000)
  • Alignment rounds the end down to 1000 (1001 / 1000 * 1000)
  • Since end is not greater than start, the chunk is dropped
  • Zero partitions remain, and n_chunks = 0
  • The summary then divides by n_chunks to compute percentages, causing the panic

Solution

Guard the percentage-printing block behind n_chunks > 0. When there are no chunks, the summary still prints total chunks: 0 but skips the errored/skipped/collected breakdown that requires division.

Fixes #150

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

…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
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.

Attempt to divide by 0 when using --align for method "contracts" with block range 1:1001

1 participant