Skip to content

feat: added switcher.default_result() fall back feature#30

Merged
petruki merged 1 commit intomasterfrom
staging
Feb 14, 2026
Merged

feat: added switcher.default_result() fall back feature#30
petruki merged 1 commit intomasterfrom
staging

Conversation

@petruki
Copy link
Member

@petruki petruki commented Feb 14, 2026

This pull request introduces support for setting a default result when feature flag criteria evaluation fails, both for local and remote strategies. This ensures that the application can gracefully handle errors by returning a predefined result instead of raising exceptions, and provides improved error notification and logging. The PR also updates documentation and adds comprehensive tests for these new behaviors.

Default result support and error handling:

  • Added a default_result method to the Switcher class, allowing users to specify a fallback result if criteria evaluation fails. The implementation ensures that, in case of errors (e.g., missing config, remote API failure), the default result is returned and the error is logged or notified. (switcher_client/switcher_data.py [1] [2]; switcher_client/switcher.py [3]
  • Introduced the _get_default_result_or_raise helper to encapsulate fallback logic and error notification when criteria checks fail. (switcher_client/switcher.py switcher_client/switcher.pyR93-R125)
  • Added a static create method to ResultDetail for easier instantiation in fallback scenarios. (switcher_client/lib/types.py switcher_client/lib/types.pyR9-R12)

Documentation updates:

  • Updated the README.md to demonstrate chaining of validation strategies, including the new default_result and throttle methods for robust feature control. (README.md README.mdL212-R220)

Testing improvements:

  • Added tests to verify that default_result is correctly returned on local and remote evaluation failures, and that error notifications are triggered as expected. (tests/test_switcher_local.py [1] [2] [3]; tests/test_switcher_remote.py [4] [5]

@petruki petruki self-assigned this Feb 14, 2026
@petruki petruki added the enhancement New feature or request label Feb 14, 2026
@sonarqubecloud
Copy link

@petruki petruki merged commit 18dc58f into master Feb 14, 2026
15 checks passed
@petruki petruki deleted the staging branch February 14, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant