Skip to content

Commit afa3e05

Browse files
authored
Allow defining not supported variables (#210)
* Allow defining not supported variables * Unit test
1 parent f57bae4 commit afa3e05

File tree

5 files changed

+75
-12
lines changed

5 files changed

+75
-12
lines changed

Runtime/Attributes.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Backtrace.Unity.Attributes
4+
{
5+
[Obsolete("Not supported")]
6+
public class NotSupportedAttribute : Attribute
7+
{
8+
}
9+
}

Runtime/Attributes/NotSupportedAttribute.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Model/BacktraceConfiguration.cs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Backtrace.Unity.Common;
1+
using Backtrace.Unity.Attributes;
2+
using Backtrace.Unity.Common;
23
using Backtrace.Unity.Model.Breadcrumbs;
34
using Backtrace.Unity.Services;
45
using Backtrace.Unity.Types;
@@ -125,7 +126,6 @@ public class BacktraceConfiguration : ScriptableObject
125126
[Tooltip("Try to find game native crashes and send them on Game startup")]
126127
public bool SendUnhandledGameCrashesOnGameStartup = true;
127128

128-
#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN || UNITY_GAMECORE_XBOXSERIES
129129
#if UNITY_ANDROID
130130
/// <summary>
131131
/// Capture native NDK Crashes.
@@ -136,47 +136,66 @@ public class BacktraceConfiguration : ScriptableObject
136136
/// Capture native crashes.
137137
/// </summary>
138138
[Tooltip("Capture native Crashes")]
139+
#else
140+
/// <summary>
141+
/// Capture native crashes.
142+
/// </summary>
143+
[NotSupported]
139144
#endif
140-
141145
public bool CaptureNativeCrashes = true;
142-
#if !UNITY_GAMECORE_XBOXSERIES
146+
143147
/// <summary>
144148
/// Handle ANR events - Application not responding
145149
/// </summary>
150+
#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN
146151
[Tooltip("Capture ANR events - Application not responding")]
147-
public bool HandleANR = true;
152+
#else
153+
[NotSupported]
148154
#endif
155+
public bool HandleANR = true;
156+
149157

150158
/// <summary>
151159
/// Anr watchdog timeout in ms. Time needed to detect an ANR event
152160
/// </summary>
161+
#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_WIN
162+
[Tooltip("ANR watchdog timeout")]
163+
#else
164+
[NotSupported]
165+
#endif
153166
public int AnrWatchdogTimeout = DefaultAnrWatchdogTimeout;
154167

155-
#if UNITY_ANDROID || UNITY_IOS
156168
/// <summary>
157169
/// Send Out of memory exceptions to Backtrace.
158170
/// </summary>
171+
#if UNITY_ANDROID || UNITY_IOS
159172
[Tooltip("Send Out of Memory exceptions to Backtrace")]
173+
#else
174+
[NotSupported]
175+
#endif
160176
public bool OomReports = false;
161177

162-
#if UNITY_2019_2_OR_NEWER
163178
/// <summary>
164179
/// Enable client side unwinding.
165180
/// </summary>
181+
#if UNITY_2019_2_OR_NEWER && (UNITY_ANDROID || UNITY_IOS)
166182
[Tooltip("Enable client-side unwinding.")]
167-
public bool ClientSideUnwinding = false;
183+
#else
184+
[NotSupported]
168185
#endif
186+
public bool ClientSideUnwinding = false;
169187

170-
#endif
171188

172-
#if UNITY_2019_2_OR_NEWER && UNITY_ANDROID
173189
/// <summary>
174190
/// Symbols upload token
175191
/// </summary>
192+
#if UNITY_2019_2_OR_NEWER && UNITY_ANDROID
176193
[Tooltip("Symbols upload token required to upload symbols to Backtrace")]
177-
public string SymbolsUploadToken = string.Empty;
178-
#endif
194+
#else
195+
[NotSupported]
179196
#endif
197+
public string SymbolsUploadToken = string.Empty;
198+
180199

181200
/// <summary>
182201
/// Backtrace client deduplication strategy.

Tests/Runtime/BacktraceClientTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ public void Setup()
1818
AfterSetup(false);
1919
}
2020

21+
[UnityTest]
22+
public IEnumerator TestClientConfigurationOptions_ValidConfigurationWithAllOptions_AllowsToUseNotSupportedOptions()
23+
{
24+
var clientConfiguration = GetValidClientConfiguration();
25+
clientConfiguration.OomReports = false;
26+
clientConfiguration.HandleANR = false;
27+
clientConfiguration.AnrWatchdogTimeout = 0;
28+
clientConfiguration.CaptureNativeCrashes = false;
29+
clientConfiguration.ClientSideUnwinding = false;
30+
clientConfiguration.SymbolsUploadToken = string.Empty;
31+
BacktraceClient.Configuration = clientConfiguration;
32+
BacktraceClient.Refresh();
33+
Assert.IsTrue(BacktraceClient.Enabled);
34+
yield return null;
35+
}
36+
2137
[UnityTest]
2238
public IEnumerator TestClientCreation_ValidBacktraceConfiguration_ValidClientCreation()
2339
{

0 commit comments

Comments
 (0)