Skip to content

Commit 19b5a7e

Browse files
authored
Ignore null value on CocoaScopeObserver.SetTag (#3948)
1 parent aa5c432 commit 19b5a7e

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Fixed envelopes with oversized attachments getting stuck in __processing ([#3938](https://github.com/getsentry/sentry-dotnet/pull/3938))
1010
- Unknown stack frames in profiles on .NET 8+ ([#3942](https://github.com/getsentry/sentry-dotnet/pull/3942))
1111
- Deduplicate profiling stack frames ([#3941](https://github.com/getsentry/sentry-dotnet/pull/3941))
12+
- Ignore null value on CocoaScopeObserver.SetTag ([#3948](https://github.com/getsentry/sentry-dotnet/pull/3948))
1213

1314
## 5.1.0
1415

src/Sentry/Platforms/Cocoa/CocoaScopeObserver.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ public void SetExtra(string key, object? value)
6767

6868
public void SetTag(string key, string value)
6969
{
70+
if (value is null)
71+
{
72+
_options.LogDebug("Tag with key '{0}' was null. Use Unset to remove tags instead.", key);
73+
return;
74+
}
75+
7076
try
7177
{
7278
SentryCocoaSdk.ConfigureScope(scope => scope.SetTagValue(value, key));

test/Sentry.Tests/ScopeTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,24 @@ public void Filtered_tags_are_not_set()
615615

616616
scope.Tags.Should().OnlyContain(pair => pair.Key == "AzFunctions" && pair.Value == "rule");
617617
}
618+
619+
[Fact]
620+
public void SetTag_NullValue_DoesNotThrowArgumentNullException()
621+
{
622+
var scope = new Scope();
623+
624+
ArgumentNullException exception = null;
625+
try
626+
{
627+
scope.SetTag("IAmNull", null);
628+
}
629+
catch (ArgumentNullException e)
630+
{
631+
exception = e;
632+
}
633+
634+
Assert.Null(exception);
635+
}
618636
}
619637

620638
public static class ScopeTestExtensions

0 commit comments

Comments
 (0)