feat: return error from GetFromContext when environment not found#4745
Merged
Conversation
Changes GetFromContext to return an error when a specific environment is requested from context but cannot be found, instead of silently falling back to the default environment. This makes the API more explicit and consistent with error handling patterns. The error is only returned when an environment is explicitly specified in the context but not found. If no environment is specified, it still returns the default environment without error. - Modified GetFromContext signature to return (Environment, error) - Updated all interface definitions - Updated all call sites to handle the error appropriately - Regenerated mocks with new signature - Updated tests to expect the error return value Implements suggestion from PR #4732 Signed-off-by: markphelps <[email protected]>
markphelps
force-pushed
the
error-on-missing-env-context
branch
from
September 13, 2025 14:25
fc3cb6f to
0766a6c
Compare
|
Related Documentation Checked 3 published document(s). No updates required. You have 3 draft document(s). Publish docs to keep them always up-to-date |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## v2 #4745 +/- ##
==========================================
- Coverage 62.48% 62.44% -0.05%
==========================================
Files 132 132
Lines 15561 15576 +15
==========================================
+ Hits 9724 9727 +3
- Misses 5155 5165 +10
- Partials 682 684 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
erka
approved these changes
Sep 13, 2025
|
Documentation Updates Checked 3 published document(s). No updates required. You have 3 draft document(s). Publish docs to keep them always up-to-date |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements the suggestion from #4732 to make
GetFromContextreturn an error when a specific environment is requested but not found, instead of silently defaulting to the default environment.Changes
internal/server/environments/storage.go: UpdatedGetFromContextto return(Environment, error)instead of justEnvironmentEnvironmentStoreinterface ininternal/server/server.goandinternal/server/evaluation/server.gointernal/server/server.go- getStore methodinternal/server/evaluation/evaluation.go- Variant, Boolean, and Batch methodsinternal/server/evaluation/ofrep_bridge.go- OFREPFlagEvaluation and OFREPFlagEvaluationBulkinternal/server/evaluation/client/server.go- EvaluationSnapshotNamespaceBehavior
The error is only returned when:
When no environment is specified in the context, it still returns the default environment without error, maintaining backward compatibility.
Testing
Implements suggestion from #4732 (comment)
Closes #4732