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(android): Parse java exception name when message missing #159

Merged
merged 1 commit into from
Jul 3, 2019
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

### Bug fixes

* (Android) Fix error class and message parsing for uncaught Java exceptions
without message contents
[#159](https://github.com/bugsnag/bugsnag-unity/pull/159)
* Show report metadata added using `Bugsnag.Metadata.Add()` in native crash
reports
[#157](https://github.com/bugsnag/bugsnag-unity/pull/157)
Expand Down
2 changes: 1 addition & 1 deletion bugsnag-android
Submodule bugsnag-android updated 181 files
14 changes: 13 additions & 1 deletion src/BugsnagUnity/Payload/Exception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,28 @@ public static Exception FromUnityLogMessage(UnityLogMessage logMessage, System.D
{
var errorClass = match.Groups["errorClass"].Value;
var message = match.Groups["message"].Value.Trim();
// Exceptions starting with "AndroidJavaException" are uncaught Java exceptions reported
// via the Unity log handler
if (errorClass == AndroidJavaErrorClass)
{
match = Regex.Match(message, ErrorClassMessagePattern, RegexOptions.Singleline);

// If the message matches the "class: message" pattern, then the Java class is followed
// by a description of the Java exception. These two values will be used as the error
// class and message.
if (match.Success)
{
errorClass = match.Groups["errorClass"].Value;
message = match.Groups["message"].Value.Trim();
lines = new StackTrace(logMessage.StackTrace, StackTraceFormat.AndroidJava).ToArray();
}
else
{
// There was no Java exception description, so the Java class is the only content in
// the message.
errorClass = message;
message = "";
}
lines = new StackTrace(logMessage.StackTrace, StackTraceFormat.AndroidJava).ToArray();
handledState = HandledState.ForUnhandledException();
}
return new Exception(errorClass, message, lines, handledState);
Expand Down
22 changes: 22 additions & 0 deletions tests/BugsnagUnity.Tests/ExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ public void ParseExceptionFromLogMessage()

[Test]
public void ParseAndroidExceptionFromLogMessage()
{
string condition = "AndroidJavaException: java.lang.IllegalArgumentException";
string stacktrace = @"java.lang.IllegalArgumentException
com.example.bugsnagcrashplugin.CrashHelper.UnhandledCrash(CrashHelper.java:11)
com.unity3d.player.UnityPlayer.nativeRender(Native Method)";
var logType = UnityEngine.LogType.Error;
var log = new UnityLogMessage(condition, stacktrace, logType);
var exception = Exception.FromUnityLogMessage(log, new System.Diagnostics.StackFrame[] {}, Severity.Warning);
var stack = exception.StackTrace.ToList();
Assert.AreEqual("java.lang.IllegalArgumentException", exception.ErrorClass);
Assert.True(System.String.IsNullOrEmpty(exception.ErrorMessage));
Assert.AreEqual(2, stack.Count);
Assert.AreEqual("com.example.bugsnagcrashplugin.CrashHelper.UnhandledCrash()", stack[0].Method);
Assert.AreEqual("CrashHelper.java", stack[0].File);
Assert.AreEqual(11, stack[0].LineNumber);
Assert.AreEqual("com.unity3d.player.UnityPlayer.nativeRender()", stack[1].Method);
Assert.AreEqual("Native Method", stack[1].File);
Assert.AreEqual(null, stack[1].LineNumber);
}

[Test]
public void ParseAndroidExceptionAndMessageFromLogMessage()
{
string condition = "AndroidJavaException: java.lang.ArrayIndexOutOfBoundsException: length=2; index=2";
string stacktrace = @"java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
Expand Down