Skip to content

Commit 6440eb9

Browse files
committed
Version 2.1.4: Handle nullable environment variables and attributes
1 parent baa393d commit 6440eb9

File tree

6 files changed

+51
-5
lines changed

6 files changed

+51
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Backtrace Unity Release Notes
22

3+
## Version 2.1.4
4+
5+
- `EnvironmentVariable` class now will handle correctly nullable key/values,
6+
- `BacktraceAttributes` handle correctly nullable values.
7+
38
## Version 2.1.3
49

510
- `BacktraceUnhandledException` will generate environment stack trace if Unity stack trace is empty. BacktraceReport will still generate normalized fingerprint for unhandled exception without stack trace.

Runtime/Model/BacktraceData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private void SetReportInformation()
211211
LangVersion = "Mono";
212212
#endif
213213

214-
AgentVersion = "2.1.3";
214+
AgentVersion = "2.1.4";
215215
Classifier = Report.ExceptionTypeReport ? new[] { Report.Classifier } : null;
216216
}
217217
}

Runtime/Model/JsonData/BacktraceAttributes.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,20 @@ public BacktraceJObject ToJson()
6565
var attr = new BacktraceJObject();
6666
foreach (var attribute in Attributes)
6767
{
68-
if (attribute.Value != null && attribute.Value.GetType() == typeof(bool))
68+
if(attribute.Key == null)
69+
{
70+
continue;
71+
}
72+
if(attribute.Value == null)
73+
{
74+
attr[attribute.Key] = "null";
75+
continue;
76+
}
77+
if (attribute.Value.GetType() == typeof(bool))
6978
{
7079
attr[attribute.Key] = (bool)attribute.Value;
7180
}
72-
else if (attribute.Value != null && TypeHelper.IsNumeric(attribute.Value.GetType()))
81+
else if (TypeHelper.IsNumeric(attribute.Value.GetType()))
7382
{
7483
attr[attribute.Key] = Convert.ToInt64(attribute.Value);
7584
}
@@ -158,6 +167,16 @@ private void ConvertAttributes(BacktraceReport report, Dictionary<string, object
158167
var attributes = BacktraceReport.ConcatAttributes(report, clientAttributes);
159168
foreach (var attribute in attributes)
160169
{
170+
if (attribute.Key == null)
171+
{
172+
continue;
173+
}
174+
if (attribute.Value == null)
175+
{
176+
Attributes.Add(attribute.Key, null);
177+
continue;
178+
}
179+
161180
var type = attribute.Value.GetType();
162181
if (type.IsPrimitive || type == typeof(string) || type.IsEnum)
163182
{

Runtime/Model/JsonData/EnvironmentVariables.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ private void ReadEnvironmentVariables()
3030
{
3131
foreach (DictionaryEntry variable in Environment.GetEnvironmentVariables())
3232
{
33-
Variables.Add(variable.Key.ToString(), Regex.Escape(variable.Value.ToString() ?? "NULL"));
33+
if (variable.Key == null)
34+
{
35+
continue;
36+
}
37+
var key = variable.Key.ToString();
38+
var value = variable.Value == null
39+
? "NULL"
40+
: Regex.Escape(variable.Value.ToString());
41+
Variables.Add(key, value);
3442
}
3543
}
3644
}

Tests/Runtime/BacktraceReportTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,21 @@ public IEnumerator TestReportCreation_CreateCorrectReport_WithDiffrentConstructo
3333
Assert.DoesNotThrow(() => new BacktraceReport(exception, attachmentPaths: attachemnts));
3434
yield return null;
3535
}
36+
[Test]
37+
public void TestReportCreation_ShouldCreateReportWithNullableAttributes_ReportCreationWorks()
38+
{
39+
var exception = new FileNotFoundException();
40+
string nullableValue = null;
41+
string value = "value";
42+
var report = new BacktraceReport(exception, new Dictionary<string, object>() { { value, nullableValue } });
43+
var data = report.ToBacktraceData(null);
3644

45+
Assert.AreEqual(data.Attributes.Attributes[value], nullableValue);
46+
47+
Assert.DoesNotThrow(() => data.ToJson());
48+
49+
50+
}
3751
[UnityTest]
3852
public IEnumerator TestReportSerialization_SerializeValidReport_ExceptionReport()
3953
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "io.backtrace.unity",
33
"displayName": "Backtrace",
4-
"version": "2.1.3",
4+
"version": "2.1.4",
55
"unity": "2017.1",
66
"description": "Backtrace's integration with Unity games allows customers to capture and report handled and unhandled Unity exceptions to their Backtrace instance, instantly offering the ability to prioritize and debug software errors.",
77
"keywords": [

0 commit comments

Comments
 (0)