Skip to content
Snippets Groups Projects
Commit d3a23e92 authored by Drahomír Karchňák's avatar Drahomír Karchňák
Browse files

#434 Sentry now sends IOSExceptions aswell...

parent 9ee399d7
Branches
Tags
No related merge requests found
...@@ -10,6 +10,8 @@ import com.getsentry.raven.event.Event; ...@@ -10,6 +10,8 @@ import com.getsentry.raven.event.Event;
import com.getsentry.raven.event.EventBuilder; import com.getsentry.raven.event.EventBuilder;
import com.getsentry.raven.event.helper.EventBuilderHelper; import com.getsentry.raven.event.helper.EventBuilderHelper;
import com.getsentry.raven.event.interfaces.ExceptionInterface; import com.getsentry.raven.event.interfaces.ExceptionInterface;
import com.getsentry.raven.event.interfaces.SentryInterface;
import com.getsentry.raven.event.interfaces.StackTraceInterface;
import net.engio.mbassy.listener.Handler; import net.engio.mbassy.listener.Handler;
...@@ -32,6 +34,13 @@ import cz.nic.tablexia.screen.AbstractTablexiaScreen; ...@@ -32,6 +34,13 @@ import cz.nic.tablexia.screen.AbstractTablexiaScreen;
* Created by drahomir on 7/28/16. * Created by drahomir on 7/28/16.
*/ */
public class TablexiaRaven { public class TablexiaRaven {
private static final String EXCEPTION_TYPE_TAG_NAME = "ExceptionType";
public enum ExceptionType {
JavaException,
IOSException
}
/** /**
* Custom raven factory which allows to set EventSendFailureCallback * Custom raven factory which allows to set EventSendFailureCallback
*/ */
...@@ -203,7 +212,7 @@ public class TablexiaRaven { ...@@ -203,7 +212,7 @@ public class TablexiaRaven {
Event e = deserializeEvent(file); Event e = deserializeEvent(file);
if(e != null) { if(e != null) {
file.delete(); file.delete();
tablexiaRaven.sentEvent(e); tablexiaRaven.sendEvent(e);
} }
} }
} }
...@@ -343,11 +352,12 @@ public class TablexiaRaven { ...@@ -343,11 +352,12 @@ public class TablexiaRaven {
} }
} }
private void sendExceptionEvent(Thread t, Throwable e) { private void buildAndSendExceptionEvent(String message, SentryInterface sentryInterface, ExceptionType exceptionType) {
EventBuilder eventBuilder = new EventBuilder() EventBuilder eventBuilder = new EventBuilder()
.withMessage(e.getMessage()) .withMessage(message)
.withSentryInterface(new ExceptionInterface(e)) .withSentryInterface(sentryInterface)
.withLevel(Event.Level.ERROR); .withLevel(Event.Level.ERROR)
.withTag(EXCEPTION_TYPE_TAG_NAME, exceptionType.toString());
for(Info info : Info.values()) { for(Info info : Info.values()) {
info.insert(tablexiaEventBuilderHelper); info.insert(tablexiaEventBuilderHelper);
...@@ -355,11 +365,19 @@ public class TablexiaRaven { ...@@ -355,11 +365,19 @@ public class TablexiaRaven {
raven.runBuilderHelpers(eventBuilder); raven.runBuilderHelpers(eventBuilder);
raven.sendEvent(eventBuilder.build()); raven.sendEvent(eventBuilder.build());
Gdx.app.exit(); Gdx.app.exit();
} }
private void sentEvent(Event e) { private void sendExceptionEvent(Thread t, Throwable e) {
buildAndSendExceptionEvent(e.getMessage(), new ExceptionInterface(e), ExceptionType.JavaException);
}
public static void sendCustomException(ExceptionType exceptionType, String msg, StackTraceElement[] stackTraceElements) {
if(!isStarted()) return;
instance.buildAndSendExceptionEvent(msg, new StackTraceInterface(stackTraceElements), exceptionType);
}
private void sendEvent(Event e) {
if(isStarted() && e != null) instance.raven.sendEvent(e); if(isStarted() && e != null) instance.raven.sendEvent(e);
} }
......
...@@ -5,6 +5,8 @@ import com.badlogic.gdx.Gdx; ...@@ -5,6 +5,8 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.iosrobovm.IOSApplication; import com.badlogic.gdx.backends.iosrobovm.IOSApplication;
import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration; import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration;
import org.robovm.apple.foundation.NSException;
import org.robovm.objc.block.VoidBlock1;
import org.robovm.apple.foundation.NSAutoreleasePool; import org.robovm.apple.foundation.NSAutoreleasePool;
import org.robovm.apple.foundation.NSBundle; import org.robovm.apple.foundation.NSBundle;
import org.robovm.apple.foundation.NSDictionary; import org.robovm.apple.foundation.NSDictionary;
...@@ -66,10 +68,29 @@ public class IOSLauncher extends IOSApplication.Delegate { ...@@ -66,10 +68,29 @@ public class IOSLauncher extends IOSApplication.Delegate {
@Override @Override
public boolean didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) { public boolean didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) {
boolean result = super.didFinishLaunching(application, launchOptions); boolean result = super.didFinishLaunching(application, launchOptions);
registerUncaughtExceptionHandler();
Gdx.files = tablexiaIOSFiles; Gdx.files = tablexiaIOSFiles;
return result; return result;
} }
private void registerUncaughtExceptionHandler() {
NSException.setUncaughtExceptionHandler(new VoidBlock1<NSException>() {
@Override
public void invoke(final NSException e) {
String exceptionMsg = e.getName() + ": " + e.getReason();
StackTraceElement[] elements = new StackTraceElement[e.getCallStackSymbols().size()];
for(int i = 0; i < elements.length; i++) {
elements[i] = new StackTraceElement(e.getCallStackSymbols().get(i).toString(), "", "", 0);
}
TablexiaRaven.sendCustomException(TablexiaRaven.ExceptionType.IOSException, exceptionMsg, elements);
}
});
}
public static void main(String[] argv) { public static void main(String[] argv) {
NSAutoreleasePool pool = new NSAutoreleasePool(); NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(argv, null, IOSLauncher.class); UIApplication.main(argv, null, IOSLauncher.class);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment