Skip to content

fix(email): avoid 'NaN B' file size for zero-byte uploads#107

Merged
rubenhensen merged 1 commit intomainfrom
fix/format-file-size-zero
Apr 24, 2026
Merged

fix(email): avoid 'NaN B' file size for zero-byte uploads#107
rubenhensen merged 1 commit intomainfrom
fix/format-file-size-zero

Conversation

@dobby-coder
Copy link
Copy Markdown
Contributor

@dobby-coder dobby-coder Bot commented Apr 23, 2026

Summary

Refs #37 (the screenshot showed NaN B as the displayed file size in a notification email).

format_file_size computed log10(0) = -inf, which casts to i32::MIN, then 1024.powi(i32::MIN) = 0, so the division produced NaN. The email template rendered NaN B. Extremely large sizes past TB would also index out of UNITS (no crash, but wrong unit).

Fix

  • size == 0 → short-circuit to "0 B".
  • Clamp the computed index to the last UNITS slot so u64::MAX still yields a sensible <number> TB string.

Tests (7 new)

  • Zero, sub-KB (1, 1023), KB/MB/GB/TB round numbers, u64::MAX.
  • All 12 tests pass (cargo test).

Caveats

This is a defensive fix for the visible symptom. The underlying question from #37 — why does S3 storage sometimes result in state.uploaded == 0 at email time? — is a separate investigation. With this merge, if the upstream issue recurs the recipient sees 0 B instead of NaN B, which is less confusing but still indicates something is wrong.

Reviewer quickstart

git fetch origin && git checkout fix/format-file-size-zero && cargo test

Refs #37.

format_file_size(0) computed log10(0) = -inf, which cast to i32 saturates
to i32::MIN, then 1024.powi(i32::MIN) is 0, so the division produces NaN
and the email showed "NaN B". Extremely large sizes (past TB) would also
index out of bounds into UNITS.

Short-circuit size == 0 to "0 B" and clamp the computed index to the
last unit so u64::MAX stays in-range. Adds 7 unit tests covering 0, sub-
KB, KB/MB/GB/TB round numbers, and u64::MAX.

This does not address the root cause reported in #37 — whatever code
path produces size == 0 when S3 storage is in use — but it turns the
visible NaN into a benign "0 B" so recipients at least see something
sensible if the upstream issue recurs.
@rubenhensen rubenhensen marked this pull request as ready for review April 24, 2026 07:26
@rubenhensen rubenhensen merged commit 699d747 into main Apr 24, 2026
5 checks passed
@rubenhensen rubenhensen deleted the fix/format-file-size-zero branch April 24, 2026 07:26
@dobby-coder
Copy link
Copy Markdown
Contributor Author

dobby-coder Bot commented Apr 24, 2026

Dobby sees the approval! Dobby is so happy — a kind master has approved Dobby's pull request! Dobby will now check if there is anything left to do, like merging or follow-ups. Dobby serves faithfully!

@dobby-coder
Copy link
Copy Markdown
Contributor Author

dobby-coder Bot commented Apr 24, 2026

Dobby checked the PR state — it is already merged. All CI checks passed (Build amd64, Build arm64, Finalize Docker manifest) and the approval is in. No follow-up actions needed on this branch. Thank you for the review!

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