diff --git a/CHANGELOG.md b/CHANGELOG.md index f5e7672df..68f02dc8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,9 @@ ## Unreleased -### Fix +### Fixes +- Removed editor flag checks from options validation during build process ([#295](https://github.com/getsentry/sentry-unity/pull/295)) - By default, don't block Sentry.Init up to 2 seconds to flush events ([#291](https://github.com/getsentry/sentry-unity/pull/291)) ## 0.5.0 diff --git a/src/Sentry.Unity.Editor.iOS/BuildPostProcess.cs b/src/Sentry.Unity.Editor.iOS/BuildPostProcess.cs index 49899e79d..d7b283791 100644 --- a/src/Sentry.Unity.Editor.iOS/BuildPostProcess.cs +++ b/src/Sentry.Unity.Editor.iOS/BuildPostProcess.cs @@ -1,5 +1,6 @@ using System; using Sentry.Extensibility; +using Sentry.Infrastructure; using UnityEditor; using UnityEditor.Callbacks; @@ -16,8 +17,10 @@ public static void OnPostProcessBuild(BuildTarget target, string pathToProject) } var options = ScriptableSentryUnityOptions.LoadSentryUnityOptions(); - if (!options.ShouldInitializeSdk()) + if (!options.Validate()) { + new UnityLogger(new SentryOptions()).LogWarning( + "Failed to validate Sentry Options. Xcode project will not be modified."); return; } diff --git a/src/Sentry.Unity.Editor/SentryWindow.cs b/src/Sentry.Unity.Editor/SentryWindow.cs index cab015d95..c486eb022 100644 --- a/src/Sentry.Unity.Editor/SentryWindow.cs +++ b/src/Sentry.Unity.Editor/SentryWindow.cs @@ -146,15 +146,10 @@ private void DisplayCore() { GUILayout.Label("Base Options", EditorStyles.boldLabel); - var dsn = Options.Dsn; - dsn = EditorGUILayout.TextField( + Options.Dsn = EditorGUILayout.TextField( new GUIContent("DSN", "The URL to your Sentry project. " + "Get yours on sentry.io -> Project Settings."), - dsn); - if (!string.IsNullOrWhiteSpace(dsn)) - { - Options.Dsn = dsn; - } + Options.Dsn); Options.CaptureInEditor = EditorGUILayout.Toggle( new GUIContent("Capture In Editor", "Capture errors while running in the Editor."), diff --git a/src/Sentry.Unity/SentryUnityOptionsExtensions.cs b/src/Sentry.Unity/SentryUnityOptionsExtensions.cs index a22b6ed76..4bc85057e 100644 --- a/src/Sentry.Unity/SentryUnityOptionsExtensions.cs +++ b/src/Sentry.Unity/SentryUnityOptionsExtensions.cs @@ -9,22 +9,34 @@ public static class SentryUnityOptionsExtensions internal static bool ShouldInitializeSdk(this SentryUnityOptions? options, IApplication? application = null) { - if (options is null) + if (!Validate(options)) { - new UnityLogger(new SentryOptions()).LogWarning( - "Sentry has not been configured. You can do that through the editor: Tools -> Sentry"); return false; } - if (!options.Enabled) + application ??= ApplicationAdapter.Instance; + if (!options!.CaptureInEditor && application.IsEditor) { + options.DiagnosticLogger?.LogInfo("Disabled while in the Editor."); return false; } - application ??= ApplicationAdapter.Instance; - if (!options.CaptureInEditor && application.IsEditor) + return true; + } + + internal static bool Validate(this SentryUnityOptions? options) + { + if (options is null) { - options.DiagnosticLogger?.LogInfo("Disabled while in the Editor."); + new UnityLogger(new SentryOptions()).LogWarning( + "Sentry has not been configured. You can do that through the editor: Tools -> Sentry"); + return false; + } + + if (!options.Enabled) + { + options.DiagnosticLogger?.LogDebug("Sentry SDK has been disabled." + + "\nYou can disable this log by raising the debug verbosity level above 'Debug'."); return false; } diff --git a/test/Sentry.Unity.Tests/SentryUnityOptionsExtensionsTests.cs b/test/Sentry.Unity.Tests/SentryUnityOptionsExtensionsTests.cs index 874c3b7b0..cafeef828 100644 --- a/test/Sentry.Unity.Tests/SentryUnityOptionsExtensionsTests.cs +++ b/test/Sentry.Unity.Tests/SentryUnityOptionsExtensionsTests.cs @@ -26,51 +26,51 @@ private class Fixture public void SetUp() => _fixture = new Fixture(); [Test] - public void ShouldInitializeSdk_OptionsIsNull_ReturnsFalse() + public void Validate_OptionsIsNull_ReturnsFalse() { SentryUnityOptions? options = null; - var shouldInitialize = options.ShouldInitializeSdk(); + var isValid = options.Validate(); - Assert.IsFalse(shouldInitialize); + Assert.IsFalse(isValid); } [Test] - public void ShouldInitializeSdk_OptionsDisabled_ReturnsFalse() + public void Validate_OptionsDisabled_ReturnsFalse() { _fixture.Enabled = false; var options = _fixture.GetSut(); - var shouldInitialize = options.ShouldInitializeSdk(); + var isValid = options.Validate(); - Assert.IsFalse(shouldInitialize); + Assert.IsFalse(isValid); } [Test] - public void ShouldInitializeSdk_NotCaptureInEditorAndApplicationIsEditor_ReturnsFalse() + public void Validate_DsnEmpty_ReturnsFalse() { - _fixture.CaptureInEditor = false; + _fixture.Dsn = string.Empty; var options = _fixture.GetSut(); - var shouldInitialize = options.ShouldInitializeSdk(_fixture.TestApplication); + var isValid = options.Validate(); - Assert.IsFalse(shouldInitialize); + Assert.IsFalse(isValid); } [Test] - public void ShouldInitializeSdk_DsnEmpty_ReturnsFalse() + public void ShouldInitializeSdk_CorrectlyConfiguredForEditor_ReturnsTrue() { - _fixture.Dsn = string.Empty; var options = _fixture.GetSut(); - var shouldInitialize = options.ShouldInitializeSdk(); + var shouldInitialize = options.ShouldInitializeSdk(_fixture.TestApplication); - Assert.IsFalse(shouldInitialize); + Assert.IsTrue(shouldInitialize); } [Test] - public void ShouldInitializeSdk_CorrectlyConfiguredForEditor_ReturnsTrue() + public void ShouldInitializeSdk_CorrectlyConfigured_ReturnsTrue() { + _fixture.TestApplication = new TestApplication(false); var options = _fixture.GetSut(); var shouldInitialize = options.ShouldInitializeSdk(_fixture.TestApplication); @@ -79,14 +79,14 @@ public void ShouldInitializeSdk_CorrectlyConfiguredForEditor_ReturnsTrue() } [Test] - public void ShouldInitializeSdk_CorrectlyConfigured_ReturnsTrue() + public void ShouldInitializeSdk_NotCaptureInEditorAndApplicationIsEditor_ReturnsFalse() { - _fixture.TestApplication = new TestApplication(false); + _fixture.CaptureInEditor = false; var options = _fixture.GetSut(); var shouldInitialize = options.ShouldInitializeSdk(_fixture.TestApplication); - Assert.IsTrue(shouldInitialize); + Assert.IsFalse(shouldInitialize); } } }