Skip to content

Commit eb39a3a

Browse files
fix: align NoOpProvider reason and ProviderInitializationError default error code with spec
Signed-off-by: Cristian Marta <cristian@caffe-lento.com>
1 parent c5393e2 commit eb39a3a

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

lib/open_feature/sdk/provider/no_op_provider.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Provider
2323
# * <tt>fetch_object_value</tt> - Retrieve feature flag object value
2424
#
2525
class NoOpProvider
26-
REASON_NO_OP = "No-op"
26+
REASON_NO_OP = Reason::DEFAULT
2727
NAME = "No-op Provider"
2828

2929
attr_reader :metadata

lib/open_feature/sdk/provider_initialization_error.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class ProviderInitializationError < StandardError
2121
# @param message [String] the error message
2222
# @param provider [Object] the provider that failed to initialize
2323
# @param original_error [Exception] the original error that caused the failure
24-
# @param error_code [String] the OpenFeature error code (defaults to PROVIDER_FATAL)
25-
def initialize(message, provider: nil, original_error: nil, error_code: Provider::ErrorCode::PROVIDER_FATAL)
24+
# @param error_code [String] the OpenFeature error code (defaults to GENERAL)
25+
def initialize(message, provider: nil, original_error: nil, error_code: Provider::ErrorCode::GENERAL)
2626
super(message)
2727
@provider = provider
2828
@original_error = original_error

spec/open_feature/sdk/hooks/logging_hook_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,15 @@
148148
end
149149

150150
it "uses error_code from exception when available" do
151-
error_with_code = OpenFeature::SDK::ProviderInitializationError.new("init failed")
151+
error_with_code = OpenFeature::SDK::ProviderInitializationError.new(
152+
"init failed",
153+
error_code: "CUSTOM_ERROR_CODE"
154+
)
152155
hook = described_class.new(logger: logger)
153156

154157
expect(logger).to receive(:error) do |&block|
155158
message = block.call
156-
expect(message).to include("error_code=PROVIDER_FATAL")
159+
expect(message).to include("error_code=CUSTOM_ERROR_CODE")
157160
end
158161

159162
hook.error(hook_context: hook_context, exception: error_with_code, hints: hints)

spec/open_feature/sdk/provider_initialization_error_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
expect(error).to be_a(StandardError)
3030
end
3131

32-
it "sets the error code to PROVIDER_FATAL by default" do
33-
expect(error.error_code).to eq(OpenFeature::SDK::Provider::ErrorCode::PROVIDER_FATAL)
32+
it "sets the error code to GENERAL by default" do
33+
expect(error.error_code).to eq(OpenFeature::SDK::Provider::ErrorCode::GENERAL)
3434
end
3535
end
3636

@@ -49,8 +49,8 @@
4949
expect(error.original_error).to be_nil
5050
end
5151

52-
it "sets the error code to PROVIDER_FATAL by default" do
53-
expect(error.error_code).to eq(OpenFeature::SDK::Provider::ErrorCode::PROVIDER_FATAL)
52+
it "sets the error code to GENERAL by default" do
53+
expect(error.error_code).to eq(OpenFeature::SDK::Provider::ErrorCode::GENERAL)
5454
end
5555
end
5656

0 commit comments

Comments
 (0)