Skip to content

Commit c585ee6

Browse files
authoredAug 26, 2021
fix: Removed editor flag checks from options validation (#295)
* split options should initialize check * removed dsn deletion block from sentry config window * updated CHANGELOG.md * added debug log to options being disabled * added log warning to build process in case of validation fail
1 parent ce3edb3 commit c585ee6

File tree

5 files changed

+45
-34
lines changed

5 files changed

+45
-34
lines changed
 

‎CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
## Unreleased
44

5-
### Fix
5+
### Fixes
66

7+
- Removed editor flag checks from options validation during build process ([#295](https://github.com/getsentry/sentry-unity/pull/295))
78
- By default, don't block Sentry.Init up to 2 seconds to flush events ([#291](https://github.com/getsentry/sentry-unity/pull/291))
89

910
## 0.5.0

‎src/Sentry.Unity.Editor.iOS/BuildPostProcess.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using Sentry.Extensibility;
3+
using Sentry.Infrastructure;
34
using UnityEditor;
45
using UnityEditor.Callbacks;
56

@@ -16,8 +17,10 @@ public static void OnPostProcessBuild(BuildTarget target, string pathToProject)
1617
}
1718

1819
var options = ScriptableSentryUnityOptions.LoadSentryUnityOptions();
19-
if (!options.ShouldInitializeSdk())
20+
if (!options.Validate())
2021
{
22+
new UnityLogger(new SentryOptions()).LogWarning(
23+
"Failed to validate Sentry Options. Xcode project will not be modified.");
2124
return;
2225
}
2326

‎src/Sentry.Unity.Editor/SentryWindow.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,10 @@ private void DisplayCore()
146146
{
147147
GUILayout.Label("Base Options", EditorStyles.boldLabel);
148148

149-
var dsn = Options.Dsn;
150-
dsn = EditorGUILayout.TextField(
149+
Options.Dsn = EditorGUILayout.TextField(
151150
new GUIContent("DSN", "The URL to your Sentry project. " +
152151
"Get yours on sentry.io -> Project Settings."),
153-
dsn);
154-
if (!string.IsNullOrWhiteSpace(dsn))
155-
{
156-
Options.Dsn = dsn;
157-
}
152+
Options.Dsn);
158153

159154
Options.CaptureInEditor = EditorGUILayout.Toggle(
160155
new GUIContent("Capture In Editor", "Capture errors while running in the Editor."),

‎src/Sentry.Unity/SentryUnityOptionsExtensions.cs

+19-7
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,34 @@ public static class SentryUnityOptionsExtensions
99

1010
internal static bool ShouldInitializeSdk(this SentryUnityOptions? options, IApplication? application = null)
1111
{
12-
if (options is null)
12+
if (!Validate(options))
1313
{
14-
new UnityLogger(new SentryOptions()).LogWarning(
15-
"Sentry has not been configured. You can do that through the editor: Tools -> Sentry");
1614
return false;
1715
}
1816

19-
if (!options.Enabled)
17+
application ??= ApplicationAdapter.Instance;
18+
if (!options!.CaptureInEditor && application.IsEditor)
2019
{
20+
options.DiagnosticLogger?.LogInfo("Disabled while in the Editor.");
2121
return false;
2222
}
2323

24-
application ??= ApplicationAdapter.Instance;
25-
if (!options.CaptureInEditor && application.IsEditor)
24+
return true;
25+
}
26+
27+
internal static bool Validate(this SentryUnityOptions? options)
28+
{
29+
if (options is null)
2630
{
27-
options.DiagnosticLogger?.LogInfo("Disabled while in the Editor.");
31+
new UnityLogger(new SentryOptions()).LogWarning(
32+
"Sentry has not been configured. You can do that through the editor: Tools -> Sentry");
33+
return false;
34+
}
35+
36+
if (!options.Enabled)
37+
{
38+
options.DiagnosticLogger?.LogDebug("Sentry SDK has been disabled." +
39+
"\nYou can disable this log by raising the debug verbosity level above 'Debug'.");
2840
return false;
2941
}
3042

‎test/Sentry.Unity.Tests/SentryUnityOptionsExtensionsTests.cs

+18-18
Original file line numberDiff line numberDiff line change
@@ -26,51 +26,51 @@ private class Fixture
2626
public void SetUp() => _fixture = new Fixture();
2727

2828
[Test]
29-
public void ShouldInitializeSdk_OptionsIsNull_ReturnsFalse()
29+
public void Validate_OptionsIsNull_ReturnsFalse()
3030
{
3131
SentryUnityOptions? options = null;
3232

33-
var shouldInitialize = options.ShouldInitializeSdk();
33+
var isValid = options.Validate();
3434

35-
Assert.IsFalse(shouldInitialize);
35+
Assert.IsFalse(isValid);
3636
}
3737

3838
[Test]
39-
public void ShouldInitializeSdk_OptionsDisabled_ReturnsFalse()
39+
public void Validate_OptionsDisabled_ReturnsFalse()
4040
{
4141
_fixture.Enabled = false;
4242
var options = _fixture.GetSut();
4343

44-
var shouldInitialize = options.ShouldInitializeSdk();
44+
var isValid = options.Validate();
4545

46-
Assert.IsFalse(shouldInitialize);
46+
Assert.IsFalse(isValid);
4747
}
4848

4949
[Test]
50-
public void ShouldInitializeSdk_NotCaptureInEditorAndApplicationIsEditor_ReturnsFalse()
50+
public void Validate_DsnEmpty_ReturnsFalse()
5151
{
52-
_fixture.CaptureInEditor = false;
52+
_fixture.Dsn = string.Empty;
5353
var options = _fixture.GetSut();
5454

55-
var shouldInitialize = options.ShouldInitializeSdk(_fixture.TestApplication);
55+
var isValid = options.Validate();
5656

57-
Assert.IsFalse(shouldInitialize);
57+
Assert.IsFalse(isValid);
5858
}
5959

6060
[Test]
61-
public void ShouldInitializeSdk_DsnEmpty_ReturnsFalse()
61+
public void ShouldInitializeSdk_CorrectlyConfiguredForEditor_ReturnsTrue()
6262
{
63-
_fixture.Dsn = string.Empty;
6463
var options = _fixture.GetSut();
6564

66-
var shouldInitialize = options.ShouldInitializeSdk();
65+
var shouldInitialize = options.ShouldInitializeSdk(_fixture.TestApplication);
6766

68-
Assert.IsFalse(shouldInitialize);
67+
Assert.IsTrue(shouldInitialize);
6968
}
7069

7170
[Test]
72-
public void ShouldInitializeSdk_CorrectlyConfiguredForEditor_ReturnsTrue()
71+
public void ShouldInitializeSdk_CorrectlyConfigured_ReturnsTrue()
7372
{
73+
_fixture.TestApplication = new TestApplication(false);
7474
var options = _fixture.GetSut();
7575

7676
var shouldInitialize = options.ShouldInitializeSdk(_fixture.TestApplication);
@@ -79,14 +79,14 @@ public void ShouldInitializeSdk_CorrectlyConfiguredForEditor_ReturnsTrue()
7979
}
8080

8181
[Test]
82-
public void ShouldInitializeSdk_CorrectlyConfigured_ReturnsTrue()
82+
public void ShouldInitializeSdk_NotCaptureInEditorAndApplicationIsEditor_ReturnsFalse()
8383
{
84-
_fixture.TestApplication = new TestApplication(false);
84+
_fixture.CaptureInEditor = false;
8585
var options = _fixture.GetSut();
8686

8787
var shouldInitialize = options.ShouldInitializeSdk(_fixture.TestApplication);
8888

89-
Assert.IsTrue(shouldInitialize);
89+
Assert.IsFalse(shouldInitialize);
9090
}
9191
}
9292
}

0 commit comments

Comments
 (0)
Please sign in to comment.