fix!: provider exceptions crash the caller#97
Conversation
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
There was a problem hiding this comment.
Code Review
This pull request updates the FeatureProvider interface and its implementations, including InMemoryProvider and NoopProvider, to return absl::StatusOr<std::unique_ptr<...>> for all flag evaluation methods. This change standardizes error reporting and explicitly discourages the use of C++ exceptions. Corresponding updates were made to the ClientAPI, test suites, and mocks to handle the new return types. Feedback suggests adding a null check for the unique_ptr within the absl::StatusOr in openfeature/client_api.h to prevent potential crashes if a provider returns an OK status with a null pointer.
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
There was a problem hiding this comment.
Mostly LGTM. A few things:
- No tests for the 3 new branches in EvaluateFlag; cheap to add with MockFeatureProvider + a small throwing mock.
- Gemini's null-check point seems right
- I think this breaks the
FeatureProvider(correct me if I'm wrong, I'm not that strong at C++). That's totally fine since we are not 1.0, but we should use afix!:prefix.
I'll approve now, up to you to make these changes if you agree. ❤️
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAll ChangesStatusOr-based provider error propagation
Sequence DiagramsequenceDiagram
participant App
participant ClientAPI
participant FeatureProvider
App->>ClientAPI: GetBooleanValue(flag, default)
ClientAPI->>FeatureProvider: GetBooleanEvaluation(flag, default, ctx)
alt provider returns error status
FeatureProvider-->>ClientAPI: absl::StatusOr with !ok()
ClientAPI-->>App: default value (ErrorCode::kGeneral)
else provider returns null details
FeatureProvider-->>ClientAPI: absl::StatusOr with nullptr
ClientAPI-->>App: default value (ErrorCode::kGeneral)
else provider throws std::exception
FeatureProvider-->>ClientAPI: throws std::runtime_error
ClientAPI-->>App: default value (ErrorCode::kGeneral + e.what())
else provider throws unknown
FeatureProvider-->>ClientAPI: throws non-std::exception
ClientAPI-->>App: default value (ErrorCode::kGeneral)
else success
FeatureProvider-->>ClientAPI: absl::StatusOr with valid ResolutionDetails
ClientAPI-->>App: resolved flag value
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~28 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/memory_provider/in_memory_provider_test.cpp (1)
347-368: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winFail fixture setup fast when provider initialization fails.
Line 367 uses
EXPECT_TRUEinsideSetUp(). If init fails, tests continue with an invalid fixture and produce cascading failures. UseASSERT_TRUEhere.🔧 Suggested change
- EXPECT_TRUE(provider_.Init(empty_ctx_).ok()); + ASSERT_TRUE(provider_.Init(empty_ctx_).ok());🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/memory_provider/in_memory_provider_test.cpp` around lines 347 - 368, In the SetUp() method, replace the EXPECT_TRUE call that checks provider_.Init(empty_ctx_).ok() with ASSERT_TRUE instead. EXPECT_TRUE is a soft assertion that allows tests to continue even when initialization fails, leading to cascading failures with invalid fixtures. Using ASSERT_TRUE ensures the test fixture setup fails fast and stops immediately if provider initialization fails, preventing invalid state from affecting subsequent tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/memory_provider/in_memory_provider_test.cpp`:
- Around line 274-302: The test assertions for flag1 remaining after UpdateFlags
is called conflict with the documented API contract in in_memory_provider.h
which states that UpdateFlags replaces existing flags with the new
configuration. Either remove the flag1 assertion block (lines checking
flag1_res->GetValue, flag1_res->GetReason, and flag1_res->GetVariant) to align
the test with the documented behavior that UpdateFlags replaces all flags, or
update the documentation in in_memory_provider.h to clarify that UpdateFlags
merges/retains existing flags not in the updated map. Ensure the implementation,
documentation, and test assertions are consistent with a single contract.
---
Nitpick comments:
In `@test/memory_provider/in_memory_provider_test.cpp`:
- Around line 347-368: In the SetUp() method, replace the EXPECT_TRUE call that
checks provider_.Init(empty_ctx_).ok() with ASSERT_TRUE instead. EXPECT_TRUE is
a soft assertion that allows tests to continue even when initialization fails,
leading to cascading failures with invalid fixtures. Using ASSERT_TRUE ensures
the test fixture setup fails fast and stops immediately if provider
initialization fails, preventing invalid state from affecting subsequent tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 551d67b7-b256-4a30-b33b-740c70450fe6
📒 Files selected for processing (14)
openfeature/BUILDopenfeature/client_api.hopenfeature/memory_provider/in_memory_provider.cppopenfeature/memory_provider/in_memory_provider.hopenfeature/noop_provider.cppopenfeature/noop_provider.hopenfeature/provider.htest/client_api_test.cpptest/e2e/BUILDtest/e2e/context_storing_provider.cpptest/e2e/context_storing_provider.htest/memory_provider/in_memory_provider_test.cpptest/mocks/mock_feature_provider.htest/noop_provider_test.cpp
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
f85c99f to
15aa954
Compare
🤖 I have created a release *beep* *boop* --- ## [0.1.0](v0.0.2...v0.1.0) (2026-06-23) ### ⚠ BREAKING CHANGES * provider exceptions crash the caller ([#97](#97)) ### Bug Fixes * provider exceptions crash the caller ([#97](#97)) ([f4d3423](f4d3423)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Signed-off-by: OpenFeature Bot <109696520+openfeaturebot@users.noreply.github.com>
This PR
Resolves the issue where feature provider errors could propagate and crash the caller during flag evaluation.
To satisfy Requirement 1.4.10 while strictly adhering to the Google C++ Style Guide's zero-exception rules, this PR refactors the evaluation boundary to use compile-time contractual safety:
FeatureProviderevaluation interface to returnabsl::StatusOr.Related Issues
Fixes #69
Follow-up Tasks