Repository navigation
#747 evaluateBalanceAlerts does not handle negative balances or NaN edge cases - #824
Merged
k-deejah merged 1 commit intoOct 18, 2026
Conversation
…eBalanceAlerts (Sorokit#747) Add validation guards in evaluateBalanceAlerts to detect and handle NaN, negative, non-finite, and null balance values and rule thresholds. Malformed and negative values are logged via console.warn and skipped without throwing to prevent false alerts or stream crashes. Null baselines are handled consistently across all conditions.
|
@jotel-dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
Fixes #747
Adds validation guards and logging for
null,NaN, non-finite, and negative balance values and rule thresholds inevaluateBalanceAlerts.How Invalid Values Are Handled (Skipped vs Logged vs Error)
NaN, negative balance numbers< 0, non-finite numbers likeInfinity, and malformed rule thresholds) emits a descriptive warning usingconsole.warnthat identifies the asset code, rule ID, and the invalid value.continue) rather than proceeding with direct arithmetic. This prevents false alerts (such as a negative balance-10incorrectly firing abelow: 50alert, or a negative baseline distortingchange_percent).rule.thresholdisNaN, negative, or non-finite, the rule is logged and skipped.oldFloat) exists but isNaNor negative, it is logged and skipped.nullor non-arrayrules,oldBalances,newBalances, or array elements withnullitems) without throwing exceptions, ensuring long-runningstreamAccountandcreateBalanceAlertpolling loops remain stable.oldFloat === null),belowandaboveevaluate against the initial balance alone (firing once on initial crossing if past threshold), whilechange_percentconsistently does not fire (changePercent = null) because percentage change requires a non-zero baseline.oldBalancesare handled consistently with empty baselines.Acceptance Criteria Covered