fix: report divide-by-zero on mod block instead of Not a Number#7760
Merged
walterbender merged 2 commits intoJul 9, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7760 +/- ##
=======================================
Coverage 54.60% 54.60%
=======================================
Files 172 172
Lines 57270 57273 +3
=======================================
+ Hits 31272 31275 +3
Misses 25998 25998 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Chaitu7032
approved these changes
Jul 8, 2026
rakshityadav1868
pushed a commit
to rakshityadav1868/musicblocks
that referenced
this pull request
Jul 9, 2026
…rlabs#7760) * fix: report divide-by-zero on mod block instead of Not a Number * test: verify mod block reports divide-by-zero error message
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.
Description
The
modblock on the Number palette showed the wrong toast when the divisor was zero:Not a Numberinstead ofCannot divide by zero.(the message thedivideblock correctly shows for5 / 0).Root cause was a token mismatch.
MathUtility.doModthrewError("Division by zero"), but the block-level error dispatcher only recognizes the token"DivByZeroError"(whatMathUtility.doDividethrows). The unrecognized message fell through to the defaultNANERRORMSGtoast, so the divide-by-zero case was silently misreported.Related Issue
This PR fixes #7056
PR Category
Changes Made
js/utils/mathutils.js:doModnow throws the same error tokens asdoDivide—"DivByZeroError"(was"Division by zero") for a zero divisor and"NanError"(was"Invalid number input") for non-numeric input. This matches the tokens already documented indoMod's JSDoc and lets any caller dispatch on a single, shared token.js/blocks/NumberBlocks.js:handleMathErrornow mapsDivByZeroErrortoZERODIVIDEERRORMSGbefore falling back to the default. Fixing the shared handler (rather than duplicating the divide block's inline check) means every math block routed through it gets correct divide-by-zero messaging, not justmod.js/utils/__tests__/mathutils.test.js: tightened the existingdoModzero-divisor test to assert the specificDivByZeroErrormessage, and updated the two non-numeric-input assertions to the unifiedNanErrortoken.Testing Performed
npx jest js/utils/__tests__/mathutils.test.js— all passnpx jest(full suite) — 6075/6075 pass, zero regressionsnpx eslintandnpx prettier --checkon all three changed files — cleanChecklist
Additional Notes for Reviewers
Single-topic fix. The
divideblock's behavior is unchanged and served as the reference for the correctmodbehavior.