Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
don't let user fall outside of last bucket in rollout
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoskow-ld committed Dec 24, 2019
1 parent f866ab4 commit 24b85c3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion evaluate_flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function variationForUser(r, user, flag) {
if (r.variation != null) {
// This represets a fixed variation; return it
return r.variation;
} else if (r.rollout != null) {
} else if (r.rollout != null && r.rollout.variations != null && r.rollout.variations.length > 0) {
// This represents a percentage rollout. Assume
// we're rolling out by key
const bucketBy = r.rollout.bucketBy != null ? r.rollout.bucketBy : 'key';
Expand All @@ -308,6 +308,13 @@ function variationForUser(r, user, flag) {
return variate.variation;
}
}

// The user's bucket value was greater than or equal to the end of the last bucket. This could happen due
// to a rounding error, or due to the fact that we are scaling to 100000 rather than 99999, or the flag
// data could contain buckets that don't actually add up to 100000. Rather than returning an error in
// this case (or changing the scaling, which would potentially change the results for *all* users), we
// will simply put the user in the last bucket.
return r.rollout.variations[r.rollout.variations.length - 1].variation;
}

return null;
Expand Down

0 comments on commit 24b85c3

Please sign in to comment.