From 8c9ecd4c8e50d9e8fea4a43cb39e177b2b8a7bd7 Mon Sep 17 00:00:00 2001 From: Justis Durkee Date: Mon, 15 May 2023 11:21:44 -0700 Subject: [PATCH] Handle unknown stickiness value. Co-authored-by: Renato Arruda --- lib/unleash/feature_toggle.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/unleash/feature_toggle.rb b/lib/unleash/feature_toggle.rb index 764df465..ec064b34 100644 --- a/lib/unleash/feature_toggle.rb +++ b/lib/unleash/feature_toggle.rb @@ -97,7 +97,12 @@ def sum_variant_defs_weights end def variant_salt(context, stickiness = "default") - return context.get_by_name(stickiness) if !context.nil? && stickiness != "default" + begin + return context.get_by_name(stickiness) if !context.nil? && stickiness != "default" + rescue KeyError + Unleash.logger.warn "Custom stickiness key (#{stickiness}) not found in the provided context #{context}. " \ + "Falling back to default behavior." + end return context.user_id unless context&.user_id.to_s.empty? return context.session_id unless context&.session_id.to_s.empty? return context.remote_address unless context&.remote_address.to_s.empty?