Repository navigation
feat!: make Scope.Environment non-nullable - #5587
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:
|
…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>
|
@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. |
|
@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. |
|
@jamescrosswell unless @bitsandfoxes sees any reason not to. |
|
Just need to decide what we're doing about #5197 (comment) as if would render these changes unnecessary... |
|
Made redundant/inappropriate by #5197 |
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.Changelog Entry
Scope.Environment is now non-nullable (#5587)
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