feat!: make Scope.Environment non-nullable - #5587
Open
jamescrosswell wants to merge 2 commits into
Open
jamescrosswell wants to merge 2 commits into
jamescrosswell wants to merge 2 commits into
Conversation
When no environment has been set on the scope, the getter now falls back to the environment resolved from the options (options, SENTRY_ENVIRONMENT, then the default), so it never returns null. Closes #5388 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## version7 #5587 +/- ##
===========================================
Coverage ? 74.77%
===========================================
Files ? 515
Lines ? 18908
Branches ? 3691
===========================================
Hits ? 14138
Misses ? 3893
Partials ? 877 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jamescrosswell
commented
Sep 27, 2026
…tation The nullable setter now only exists on the IEventLike face of Scope, so assigning null to the public property is a compile error. Both accessors funnel into SetEnvironment, where null means "unset". Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
jamescrosswell
marked this pull request as ready for review
September 27, 2026 22:52
Collaborator
Author
|
@ric-oliv tbh not sure we even really need this change. If it's too much effort, I'm OK to close both the PR and the open issue as won't do. |
Collaborator
Author
|
@bitsandfoxes would this cause any problems for you guys? Per my comment above to Ricardo, I'm not dead set on doing this if we don't want to. |
This branch has not been deployed
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
Scope.Environmentis now declared asstringrather thanstring?.#5365 made the setter revert
nulltoSentryOptions.Environment, but the property could still returnnull: a scope whose environment was never set had a null backing field, andSentryOptions.Environmentis itself nullable. To make the non-nullable declaration truthful:SettingLocator.GetEnvironment()(options →SENTRY_ENVIRONMENT→production/debug), the same value theEnricheralready stamps on events.null([AllowNull], so it still satisfiesIEventLike.Environment) and resets to that resolved default.Scope.Applycopies only an explicitly set environment between scopes. Otherwise the non-null getter would make??=never copy onto a cloned scope.Notes for review
version7.Applyto an event now writes the resolved default environment from the scope rather than leaving it for theEnricher. The value is identical.Populate_RouteData_SetToScopesnapshot now includesEnvironment: production, since serializing a scope reads the resolved value.Apply_Environment_Nullasserted a target scope's environment staysnull, which is no longer possible. It now asserts the options fallback.Closes #5388
🤖 Generated with Claude Code