Skip to content

Commit

Permalink
Animated: Early detection of division by zero in AnimatedDivision
Browse files Browse the repository at this point in the history
Summary:
We currently see a lot of errors happens because of division by zero in `AnimatedDivision` module. We already have a check for that in the module but it happens during the animation tick where the context of execution is already lost and it's hard to find why exactly it happens.
Adding an additional check to the constructor should trigger an error right inside render function which should make the error actionable.

Changelog: [Internal] Early crash in AnimatedDivision in case of division by zero.

Reviewed By: mdvacca

Differential Revision: D20969087

fbshipit-source-id: 0d98774b79be2cc56d468a4f56d2d7c8abf58344
  • Loading branch information
shergin authored and facebook-github-bot committed Apr 11, 2020
1 parent 46c77dc commit be78673
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Libraries/Animated/src/nodes/AnimatedDivision.js
Expand Up @@ -23,6 +23,9 @@ class AnimatedDivision extends AnimatedWithChildren {

constructor(a: AnimatedNode | number, b: AnimatedNode | number) {
super();
if (b === 0) {
console.error('Detected potential division by zero in AnimatedDivision');
}
this._a = typeof a === 'number' ? new AnimatedValue(a) : a;
this._b = typeof b === 'number' ? new AnimatedValue(b) : b;
}
Expand Down

0 comments on commit be78673

Please sign in to comment.