Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fallback for missing/empty product name #205

Merged
merged 5 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- Fallback for missing/empty product name ([#205](https://github.com/getsentry/sentry-unity/pull/205))
- Add product name to release as default ([#202](https://github.com/getsentry/sentry-unity/pull/202))
- normalize line endings ([#204](https://github.com/getsentry/sentry-unity/pull/204))

Expand Down
4 changes: 3 additions & 1 deletion src/Sentry.Unity/SentryUnity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public static void Init(SentryUnityOptions unitySentryOptions)
// Uses the game `version` as Release unless the user defined one via the Options
if (unitySentryOptions.Release == null)
{
unitySentryOptions.Release = $"{Application.productName}@{Application.version}";
unitySentryOptions.Release = string.IsNullOrWhiteSpace(Application.productName)
? $"{Application.version}"
: $"{Application.productName}@{Application.version}";
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

unitySentryOptions.DiagnosticLogger?.Log(SentryLevel.Debug,
"Setting Sentry Release to Unity App.Version: {0}",
Expand Down
41 changes: 41 additions & 0 deletions test/Sentry.Unity.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Sentry.Protocol;
using Sentry.Unity.Integrations;
using Sentry.Unity.Tests.TestBehaviours;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;
Expand Down Expand Up @@ -79,6 +80,46 @@ public IEnumerator BugFarmScene_EventCaptured_IncludesCustomRelease()
Assert.AreEqual(customRelease, testEventCapture.Events.First().Release);
}

[UnityTest]
public IEnumerator BugFarmScene_EventCaptured_IncludesApplicationVersionAsRelease_WhenProductNameWhitespace()
{
yield return SetupSceneCoroutine("1_BugFarmScene");

// arrange
PlayerSettings.productName = " ";
var testEventCapture = new TestEventCapture();
using var _ = InitSentrySdk(o =>
{
o.AddIntegration(new UnityApplicationLoggingIntegration(eventCapture: testEventCapture));
});
var testBehaviour = new GameObject("TestHolder").AddComponent<TestMonoBehaviour>();

testBehaviour.gameObject.SendMessage(nameof(testBehaviour.TestException));

// assert
Assert.AreEqual(Application.version, testEventCapture.Events.First().Release);
}

[UnityTest]
public IEnumerator BugFarmScene_EventCaptured_IncludesApplicationVersionAsRelease_WhenProductNameEmpty()
{
yield return SetupSceneCoroutine("1_BugFarmScene");

// arrange
PlayerSettings.productName = null;
var testEventCapture = new TestEventCapture();
using var _ = InitSentrySdk(o =>
{
o.AddIntegration(new UnityApplicationLoggingIntegration(eventCapture: testEventCapture));
});
var testBehaviour = new GameObject("TestHolder").AddComponent<TestMonoBehaviour>();

testBehaviour.gameObject.SendMessage(nameof(testBehaviour.TestException));

// assert
Assert.AreEqual(Application.version, testEventCapture.Events.First().Release);
}

[UnityTest]
public IEnumerator BugFarmScene_EventCaptured_IncludesApplicationInEditorOrProduction()
{
Expand Down