diff --git a/lib/open_feature/sdk/client.rb b/lib/open_feature/sdk/client.rb index d4137d18..95b3f093 100644 --- a/lib/open_feature/sdk/client.rb +++ b/lib/open_feature/sdk/client.rb @@ -56,7 +56,7 @@ def track(tracking_event_name, evaluation_context: nil, tracking_event_details: built_context = build_evaluation_context(evaluation_context) @provider.track(tracking_event_name, evaluation_context: built_context, tracking_event_details: tracking_event_details) - rescue + rescue StandardError, NotImplementedError nil end diff --git a/lib/open_feature/sdk/hooks/hook_executor.rb b/lib/open_feature/sdk/hooks/hook_executor.rb index e81b9d8a..ba85ce93 100644 --- a/lib/open_feature/sdk/hooks/hook_executor.rb +++ b/lib/open_feature/sdk/hooks/hook_executor.rb @@ -54,7 +54,7 @@ def execute(ordered_hooks:, hook_context:, hints:, &evaluate_block) else run_after_hooks(ordered_hooks, hook_context, evaluation_details, hints) end - rescue => e + rescue StandardError, NotImplementedError => e run_error_hooks(ordered_hooks, hook_context, e, hints) evaluation_details = EvaluationDetails.new( diff --git a/spec/specification/flag_evaluation_api_spec.rb b/spec/specification/flag_evaluation_api_spec.rb index c2cc9588..7b15f681 100644 --- a/spec/specification/flag_evaluation_api_spec.rb +++ b/spec/specification/flag_evaluation_api_spec.rb @@ -864,6 +864,22 @@ def expect_default(details, error_code, message = nil) expect_default(OpenFeature::SDK.build_client.fetch_boolean_details(flag_key: "flag", default_value: false), OpenFeature::SDK::Provider::ErrorCode::GENERAL, /no booleans/) end + specify "a provider that raises NotImplementedError still runs error hooks and gives finally hooks the default details" do + seen = {} + recorder = Class.new do + include OpenFeature::SDK::Hooks::Hook + + define_method(:error) { |exception:, **| seen[:error] = exception.class } + define_method(:finally) { |evaluation_details:, **| seen[:finally] = evaluation_details&.error_code } + end.new + OpenFeature::SDK.set_provider_and_wait(Class.new { def fetch_boolean_value(**) = raise(NotImplementedError, "no booleans") }.new) + + details = OpenFeature::SDK.build_client.fetch_boolean_details(flag_key: "flag", default_value: false, hooks: [recorder]) + + expect_default(details, OpenFeature::SDK::Provider::ErrorCode::GENERAL, /no booleans/) + expect(seen).to eq(error: NotImplementedError, finally: OpenFeature::SDK::Provider::ErrorCode::GENERAL) + end + specify "a provider whose hooks raise returns the default" do provider = Class.new(OpenFeature::SDK::Provider::InMemoryProvider) { def hooks = raise("hooks down") }.new("flag" => true) OpenFeature::SDK.set_provider_and_wait(provider) diff --git a/spec/specification/tracking_spec.rb b/spec/specification/tracking_spec.rb index 0f6692a1..1cc64d91 100644 --- a/spec/specification/tracking_spec.rb +++ b/spec/specification/tracking_spec.rb @@ -115,6 +115,12 @@ def metadata expect(logger).not_to have_received(:error) end + specify "track MUST NOT raise when the provider's track raises NotImplementedError" do + OpenFeature::SDK.set_provider(Class.new { def track(*, **) = raise(NotImplementedError) }.new) + + expect(OpenFeature::SDK.build_client.track("checkout")).to be_nil + end + specify "track MUST NOT raise when building the evaluation context fails" do OpenFeature::SDK.set_provider(Class.new { def track(*, **) = nil }.new) OpenFeature::SDK.set_transaction_context_propagator(