Skip to content

feat: return error from GetFromContext when environment not found#4745

Merged
markphelps merged 1 commit into
v2from
error-on-missing-env-context
Sep 13, 2025
Merged

feat: return error from GetFromContext when environment not found#4745
markphelps merged 1 commit into
v2from
error-on-missing-env-context

Conversation

@markphelps

Copy link
Copy Markdown
Collaborator

Summary

This PR implements the suggestion from #4732 to make GetFromContext return an error when a specific environment is requested but not found, instead of silently defaulting to the default environment.

Changes

  • Modified internal/server/environments/storage.go: Updated GetFromContext to return (Environment, error) instead of just Environment
  • Updated interface definitions: Modified EnvironmentStore interface in internal/server/server.go and internal/server/evaluation/server.go
  • Updated all call sites: Modified error handling in:
    • internal/server/server.go - getStore method
    • internal/server/evaluation/evaluation.go - Variant, Boolean, and Batch methods
    • internal/server/evaluation/ofrep_bridge.go - OFREPFlagEvaluation and OFREPFlagEvaluationBulk
    • internal/server/evaluation/client/server.go - EvaluationSnapshotNamespace
  • Regenerated mocks: Updated mock implementations with new signature
  • Updated tests: Modified all test cases to expect the new error return value

Behavior

The error is only returned when:

  • An environment is explicitly specified in the context (e.g., via X-Environment header)
  • AND that specific environment cannot be found

When no environment is specified in the context, it still returns the default environment without error, maintaining backward compatibility.

Testing

  • All existing tests pass
  • Tests have been updated to handle the new error return
  • Linting and formatting checks pass

Implements suggestion from #4732 (comment)

Closes #4732

@markphelps
markphelps requested a review from a team as a code owner September 13, 2025 14:24
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Sep 13, 2025
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
markphelps force-pushed the error-on-missing-env-context branch from fc3cb6f to 0766a6c Compare September 13, 2025 14:25
@dosubot

dosubot Bot commented Sep 13, 2025

Copy link
Copy Markdown

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

How did I do? Any feedback?  Join Discord

@markphelps
markphelps requested a review from erka September 13, 2025 14:26
@codecov

codecov Bot commented Sep 13, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.44%. Comparing base (0f104cb) to head (0766a6c).
⚠️ Report is 2 commits behind head on v2.

Files with missing lines Patch % Lines
internal/server/evaluation/evaluation.go 0.00% 12 Missing ⚠️
internal/server/evaluation/ofrep_bridge.go 25.00% 4 Missing and 2 partials ⚠️
internal/server/evaluation/client/server.go 25.00% 2 Missing and 1 partial ⚠️
internal/server/environments/storage.go 75.00% 1 Missing ⚠️
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     
Flag Coverage Δ
integrationtests 36.51% <30.30%> (-0.40%) ⬇️
unittests 52.56% <12.12%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@erka erka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

very nice

@erka erka added the v2 Flipt v2 label Sep 13, 2025
@markphelps
markphelps merged commit 2c4b3fe into v2 Sep 13, 2025
28 of 30 checks passed
@markphelps
markphelps deleted the error-on-missing-env-context branch September 13, 2025 21:52
@github-project-automation github-project-automation Bot moved this to Done in Flipt V2 Sep 13, 2025
@dosubot

dosubot Bot commented Sep 13, 2025

Copy link
Copy Markdown

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

How did I do? Any feedback?  Join Discord

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files. v2 Flipt v2

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants