Skip to content

fix: return error when an after hook fails - #193

Open
xgbtxy wants to merge 1 commit into
open-feature:mainfrom
xgbtxy:fix/after-hook-error-propagation
Open

xgbtxy wants to merge 1 commit into
open-feature:mainfrom
xgbtxy:fix/after-hook-error-propagation

Conversation

@xgbtxy

@xgbtxy xgbtxy commented Dec 1, 2026 •

Copy link
Copy Markdown

Summary

Per the OpenFeature Hooks Specification (Requirement 4.4.8, added in open-feature/spec#428):

If an error occurs in the after hooks, it is considered abnormal execution, and the default value MUST be returned.

In Client::evaluate (src/api/client.rs), when after_hooks returns Err(error) after a successful provider resolution, the method already sets evaluation_details = EvaluationDetails::error_reason(flag_key, T::default()), runs error_hooks, and passes the error details to finally_hooks — however, result remained Ok(details), causing get_*_value and get_*_details to return Ok(resolved_value) instead of Err(error).

Changes

  • src/api/client.rs: Make result mutable in Client::evaluate and assign result = Err(error) when self.after_hooks(...) fails, matching the before_hooks and provider-resolution error paths.
  • src/hooks/mod.rs: Add an // error on after hook unit test case inside error_hook verifying that when an after hook fails, error and finally (with EvaluationReason::Error and default value) are invoked and get_bool_value returns Err(...).

Verification

  • Verified test failed before the fix (assertion failed: result.is_err() at src/hooks/mod.rs:684).
  • cargo test: 81 unit tests + 1 doctest pass (1 doc-test ignored).
  • cargo clippy -- -D warnings and cargo fmt --check --all: pass with 0 warnings.

Signed-off-by: Yan Chen <yan8925298@gmail.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 23:09
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Client::evaluate now returns an error when an after hook fails, even if resolution succeeded. A new test checks the hook order, the arguments passed to finally, and the returned evaluation error.

Changes: Evaluation error handling

Layer / File(s) Summary
After-hook error propagation
src/api/client.rs, src/hooks/mod.rs
Client::evaluate replaces the successful resolution result with the after-hook error. The test checks that the error and finally hooks run, that finally receives false with reason Error, and that evaluation returns an error.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: maximfischuk, jbovet

Merge Risk: Minimal · up to da4dc

This change makes get_value and get_details return an error when an after hook fails, as the OpenFeature spec requires. The change is small and tested, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Client::evaluate now returns an error when an after hook fails. The summary and objectives describe the same fix to the result assignment in src/api/client.rs and the …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description states the purpose of the change: under the OpenFeature Hooks Specification, an error in an after hook must return the default value. It names the changed code in src/api/client.rs (ma…
Full details: Title check

Explanation

The title names the main change: Client::evaluate now returns an error when an after hook fails. The summary and objectives describe the same fix to the result assignment in src/api/client.rs and the new test in src/hooks/mod.rs. The title is short, specific, and uses a conventional fix: prefix.

Full details: Description check

Explanation

The description states the purpose of the change: under the OpenFeature Hooks Specification, an error in an after hook must return the default value. It names the changed code in src/api/client.rs (making result mutable and setting it to Err on after-hook failure) and the new test in src/hooks/mod.rs. It also lists verification steps. The description is directly related to the changeset.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f5b385ad-d3e5-46bd-9f49-a3778391d953
Commits

Reviewing files that changed from the base of the PR and between 3568b68 and da4dc02.

Files selected for processing: 2

  • src/api/client.rs
  • src/hooks/mod.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the change to propagate after hook failures from Client::evaluate.

No open issues 🎉

What changed in this PR

Fixes Client::evaluate so an after hook failure returns an error instead of a successful provider result, aligning it with the other evaluation error paths.

Changes:

  • Propagates the error returned by a failed after hook.
  • Adds a regression test verifying the returned error and ordered error/finally hook calls, including the default value and error reason.
File Description
src/​hooks/​mod.rs Adds regression coverage for an after hook failure.
src/​api/​client.rs Sets the evaluation result to Err(error) when an after hook fails.

Review effort: Balanced

@EmiRZx EmiRZx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix confirmed, the new test fails on main at result.is_err() and passes here. the quoted text is requirement 4.4.8, added in open-feature/spec#428, while the description links 4.4.5 and 4.3.7.

@xgbtxy

xgbtxy commented Dec 2, 2026

Copy link
Copy Markdown
Author

Thanks for verifying the fix and catching the spec reference, @EmiRZx! Updated the PR description to cite Requirement 4.4.8 (open-feature/spec#428).

@EmiRZx EmiRZx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the description now cites 4.4.8. the fix was already confirmed above, so this looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants