Skip to content

Strip zeroes for ill2cpp builds #108

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

Merged
merged 8 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -5,4 +5,5 @@
### First release through UPM

- .NET SDK setup for Unity with Unity editor configuration.
- Strip zeroes for ill2cpp builds(#108)

8 changes: 8 additions & 0 deletions src/NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
8 changes: 7 additions & 1 deletion src/Sentry.Unity/UnityEventProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private static SentryException GetException(string condition, string stackTrace)

frames.Add(new SentryStackFrame
{
FileName = TryResolveFileNameForMono(filename),
FileName = TryResolveFileNameForMono(StripZeroes(filename)),
AbsolutePath = filename,
Function = functionName,
LineNumber = lineNo,
Expand All @@ -240,6 +240,12 @@ private static SentryException GetException(string condition, string stackTrace)
};
}

// https://github.com/getsentry/sentry-unity/issues/103
private static string StripZeroes(string filename)
=> filename.Equals("<00000000000000000000000000000000>", StringComparison.OrdinalIgnoreCase)
? string.Empty
: filename;

// TODO: discuss
private static string TryResolveFileNameForMono(string fileName)
{
Expand Down
27 changes: 27 additions & 0 deletions src/test/Sentry.Unity.Tests/PlayModeTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Sentry.Unity.Tests.TestBehaviours;
using UnityEngine;
Expand Down Expand Up @@ -96,6 +97,32 @@ public IEnumerator EmptyScene_LogErrorAndException_Outputs2Events()
Assert.AreEqual(1, testEventCapture.Events.Count);
}

[UnityTest]
public IEnumerator UnityEventExceptionProcessor_ILL2CPPStackTraceFilenameWithZeroes_ShouldReturnEmptyString()
{
yield return SetupSceneCoroutine("BugFarmScene");

// arrange
var unityEventProcessor = new UnityEventExceptionProcessor();
var ill2CppUnityLogException = new UnityLogException(
"one: two",
"BugFarm.ThrowNull () (at <00000000000000000000000000000000>:0)");
var sentryEvent = new SentryEvent();

// act
unityEventProcessor.Process(ill2CppUnityLogException, sentryEvent);

// assert
Assert.NotNull(sentryEvent.SentryExceptions);

var sentryException = sentryEvent.SentryExceptions!.First();
Assert.NotNull(sentryException.Stacktrace);
Assert.Greater(sentryException.Stacktrace!.Frames.Count, 0);

var sentryExceptionFirstFrame = sentryException.Stacktrace!.Frames[0];
Assert.AreEqual(string.Empty, sentryExceptionFirstFrame.FileName);
}

private static IEnumerator SetupSceneCoroutine(string sceneName)
{
// load scene with initialized Sentry, SceneManager.LoadSceneAsync(sceneName);
Expand Down