Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
cleaning up
  • Loading branch information
Manoel Aranda Neto committed Oct 24, 2019
commit ea0cebed3163e2b0b52844328c13b8c13ebbbd00
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import io.sentry.core.ILogger;
import io.sentry.core.MainEventProcessor;
import io.sentry.core.SentryLevel;
import io.sentry.core.SentryOptions;
import java.io.File;
Expand Down Expand Up @@ -56,7 +55,7 @@ private static void createsEnvelopeDirPath(SentryOptions options, Context contex
}

private static void addProcessors(SentryOptions options, Context context) {
options.addEventProcessor(new MainEventProcessor(options));
// options.addEventProcessor(new MainEventProcessor(options));
options.addEventProcessor(new DefaultAndroidEventProcessor(context, options));
}
}
24 changes: 9 additions & 15 deletions sentry-core/src/main/java/io/sentry/core/MainEventProcessor.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package io.sentry.core;

import io.sentry.core.exception.SentryExceptionReader;
import io.sentry.core.protocol.Message;
import io.sentry.core.protocol.SentryException;
import io.sentry.core.protocol.SentryStackFrame;
import io.sentry.core.protocol.SentryStackTrace;
import io.sentry.core.util.Objects;
import java.util.ArrayList;
import java.util.List;

public class MainEventProcessor implements EventProcessor {

Expand All @@ -22,19 +16,19 @@ public SentryEvent process(SentryEvent event) {
Throwable throwable = event.getThrowable();
if (throwable != null) {

if (event.getMessage() == null) {
event.setMessage(getMessage(throwable));
}
// if (event.getMessage() == null) {
// event.setMessage(getMessage(throwable));
// }

event.setException(SentryExceptionReader.sentryExceptionReader(throwable));
event.setException(SentryExceptionReader.createSentryException(throwable));
}

return event;
}

private Message getMessage(Throwable throwable) {
Message message = new Message();
message.setFormatted(throwable.getMessage());
return message;
}
// private Message getMessage(Throwable throwable) {
// Message message = new Message();
// message.setFormatted(throwable.getMessage());
// return message;
// }
}
9 changes: 0 additions & 9 deletions sentry-core/src/main/java/io/sentry/core/SentryEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class SentryEvent implements IUnknownPropertiesConsumer {
private Map<String, String> tags = new HashMap<>();
private Map<String, Object> extra = new HashMap<>();
private Map<String, Object> unknown;
// TODO modules is missing?

SentryEvent(SentryId eventId, Date timestamp) {
this.eventId = eventId;
Expand Down Expand Up @@ -136,14 +135,6 @@ public void setThrowable(Throwable throwable) {
this.throwable = throwable;
}

public void setThreads(SentryValues<SentryThread> threads) {
this.threads = threads;
}

public void setExceptions(SentryValues<SentryException> exceptions) {
this.exception = exceptions;
}

public SentryLevel getLevel() {
return level;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public interface BeforeSecondCallback {
}

public SentryOptions() {
eventProcessors.add(new MainEventProcessor(this));
integrations.add(new UncaughtExceptionHandlerIntegration());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
import io.sentry.core.protocol.Mechanism;

/**
* A throwable decorator that holds an {@link io.sentry.core.protocol.Mechanism} related to the decorated {@link Throwable}.
* A throwable decorator that holds an {@link io.sentry.core.protocol.Mechanism} related to the
* decorated {@link Throwable}.
*/
@SuppressWarnings("serial")
public final class ExceptionMechanismThrowable extends Throwable {
private static final long serialVersionUID = 100L;

private final Mechanism exceptionMechanism;
private final Throwable throwable;

/**
* A {@link Throwable} that decorates another with a Sentry {@link Mechanism}.
*
* @param mechanism The {@link Mechanism}.
* @param throwable The {@link java.lang.Throwable}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import io.sentry.core.protocol.Mechanism;
import io.sentry.core.protocol.SentryException;
import io.sentry.core.protocol.SentryStackFrame;
import io.sentry.core.protocol.SentryStackTrace;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashSet;
import java.util.List;
Expand All @@ -19,90 +18,101 @@ public final class SentryExceptionReader {
*
* @param throwable the {@link Throwable} to build this instance from
*/
public static List<SentryException> sentryExceptionReader(final Throwable throwable) {
return sentryExceptionReader(extractExceptionQueue(throwable));
public static List<SentryException> createSentryException(final Throwable throwable) {
return createSentryException(extractExceptionQueue(throwable));
}

/**
* Creates a new instance from the given {@code exceptions}.
*
* @param exceptions a {@link Deque} of {@link SentryException} to build this instance from
*/
private static List<SentryException> sentryExceptionReader(final Deque<SentryException> exceptions) {
private static List<SentryException> createSentryException(
final Deque<SentryException> exceptions) {
return new ArrayList<>(exceptions);
}

/**
* Creates a Sentry exception based on a Java Throwable.
* <p>
* The {@code childExceptionStackTrace} parameter is used to define the common frames with the child exception
* (Exception caused by {@code throwable}).
*
* @param throwable Java exception to send to Sentry.
* @param childExceptionStackTrace StackTrace of the exception caused by {@code throwable}.
* @param exceptionMechanism The optional {@link Mechanism} of the {@code throwable}.
* Or null if none exist.
* <p>The {@code childExceptionStackTrace} parameter is used to define the common frames with the
* child exception (Exception caused by {@code throwable}).
*
* @param throwable Java exception to send to Sentry.
* @param exceptionMechanism The optional {@link Mechanism} of the {@code throwable}. Or null if
* none exist.
*/
private static SentryException sentryExceptionReader(
Throwable throwable,
StackTraceElement[] childExceptionStackTrace, // TODO: do we need that?
Mechanism exceptionMechanism) {
private static SentryException createSentryException(
Throwable throwable, Mechanism exceptionMechanism) {

Package exceptionPackage = throwable.getClass().getPackage();
String fullClassName = throwable.getClass().getName();

SentryException exception = new SentryException();

// this.exceptionMessage = throwable.getMessage();
String exceptionClassName = exceptionPackage != null
? fullClassName.replace(exceptionPackage.getName() + ".", "")
: fullClassName;
String exceptionMessage = throwable.getMessage();

String exceptionClassName =
exceptionPackage != null
? fullClassName.replace(exceptionPackage.getName() + ".", "")
: fullClassName;

String exceptionPackageName = exceptionPackage != null
? exceptionPackage.getName()
: null;
// TODO: whats about those missing fields? message, classname, packagename, ...
String exceptionPackageName = exceptionPackage != null ? exceptionPackage.getName() : null;

SentryStackTrace sentryStackTrace = new SentryStackTrace();
sentryStackTrace.setFrames(
Arrays.asList(SentryStackFrameReader.fromStackTraceElements(
throwable.getStackTrace(), null))); // TODO: cached frames

exception.setStacktrace(sentryStackTrace);
exception.setType("ValueError"); // TODO ?
// exception.setValue(); type or value is mandatory
sentryStackTrace.setFrames(getStackFrames(throwable.getStackTrace()));

exception.setStacktrace(sentryStackTrace);
exception.setType(exceptionClassName);
exception.setMechanism(exceptionMechanism);
exception.setModule(exceptionPackageName);
exception.setValue(exceptionMessage);

return exception;
}

private static List<SentryStackFrame> getStackFrames(StackTraceElement[] elements) {
List<SentryStackFrame> sentryStackFrames = new ArrayList<>();

for(StackTraceElement item : elements) {
SentryStackFrame sentryStackFrame = new SentryStackFrame();
sentryStackFrame.setModule(item.getClassName());
sentryStackFrame.setFunction(item.getMethodName());
sentryStackFrame.setFilename(item.getFileName());
sentryStackFrame.setLineno(item.getLineNumber());
sentryStackFrames.add(sentryStackFrame);
}
return sentryStackFrames;
}

/**
* Transforms a {@link Throwable} into a Queue of {@link SentryException}.
* <p>
* Exceptions are stored in the queue from the most recent one to the oldest one.
*
* <p>Exceptions are stored in the queue from the most recent one to the oldest one.
*
* @param throwable throwable to transform in a queue of exceptions.
* @return a queue of exception with StackTrace.
*/
private static Deque<SentryException> extractExceptionQueue(Throwable throwable) {
Deque<SentryException> exceptions = new ArrayDeque<>();
Set<Throwable> circularityDetector = new HashSet<>();
StackTraceElement[] childExceptionStackTrace = new StackTraceElement[0];
Mechanism exceptionMechanism = null;
Mechanism exceptionMechanism;

//Stack the exceptions to send them in the reverse order
// Stack the exceptions to send them in the reverse order
while (throwable != null && circularityDetector.add(throwable)) {
if (throwable instanceof ExceptionMechanismThrowable) {
ExceptionMechanismThrowable exceptionMechanismThrowable = (ExceptionMechanismThrowable) throwable;
// this is for ANR I believe
ExceptionMechanismThrowable exceptionMechanismThrowable =
(ExceptionMechanismThrowable) throwable;
exceptionMechanism = exceptionMechanismThrowable.getExceptionMechanism();
throwable = exceptionMechanismThrowable.getThrowable();
} else {
exceptionMechanism = null;
}

SentryException exception = sentryExceptionReader(throwable, childExceptionStackTrace, exceptionMechanism);
SentryException exception = createSentryException(throwable, exceptionMechanism);
exceptions.add(exception);
childExceptionStackTrace = throwable.getStackTrace();
throwable = throwable.getCause();
}

Expand Down

This file was deleted.

Loading