This repository was archived by the owner on Aug 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 30
feat stacktraces and exceptions #61
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ccb80f6
created MainEventProcessor
a98da12
WIP
ee4f571
WIP
7733648
fix merge conflict
199de95
fixing protocol names
affa3cb
parsing stacktraces
13d48b7
WIP
9f09714
removed frame cache
ea0cebe
cleaning up
9a62459
fix merge conflict
69aea15
ref stacktraces and exceptions
b0ef08a
code review
marandaneto 224a099
Merge branch 'master' into feat/stacktraces
marandaneto a7ff3aa
fix assert
marandaneto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ref stacktraces and exceptions
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
sentry-core/src/main/java/io/sentry/core/SentryStackTraceFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package io.sentry.core; | ||
|
|
||
| import io.sentry.core.protocol.SentryStackFrame; | ||
| import io.sentry.core.util.Nullable; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** class responsible for converting Java StackTraceElements to SentryStackFrames */ | ||
| class SentryStackTraceFactory { | ||
|
|
||
| /** | ||
| * convert an Array of Java StackTraceElements to a list of SentryStackFrames | ||
| * | ||
| * @param elements Array of Java StackTraceElements | ||
| * @return list of SentryStackFrames | ||
| */ | ||
| List<SentryStackFrame> getStackFrames(@Nullable final StackTraceElement[] elements) { | ||
| List<SentryStackFrame> sentryStackFrames = new ArrayList<>(); | ||
|
|
||
| if (elements != null) { | ||
| for (StackTraceElement item : elements) { | ||
| SentryStackFrame sentryStackFrame = new SentryStackFrame(); | ||
| sentryStackFrame.setModule(item.getClassName()); | ||
| sentryStackFrame.setFunction(item.getMethodName()); | ||
| sentryStackFrame.setFilename(item.getFileName()); | ||
| sentryStackFrame.setLineno(item.getLineNumber()); | ||
| sentryStackFrame.setNative(item.isNativeMethod()); | ||
|
|
||
| sentryStackFrames.add(sentryStackFrame); | ||
| } | ||
| } | ||
|
|
||
| return sentryStackFrames; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
sentry-core/src/test/java/io/sentry/core/SentryExceptionFactoryTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package io.sentry.core | ||
|
|
||
| import io.sentry.core.exception.ExceptionMechanismThrowable | ||
| import io.sentry.core.protocol.Mechanism | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertTrue | ||
|
|
||
| class SentryExceptionFactoryTest { | ||
| private val sut = SentryExceptionFactory() | ||
|
|
||
| @Test | ||
| fun `when getSentryExceptions is called passing an Exception, not empty result`() { | ||
| val exception = Exception("Exception") | ||
| assertTrue(sut.getSentryExceptions(exception).size > 0) | ||
| } | ||
|
|
||
| @Test | ||
| fun `when getSentryExceptions is called passing null, empty result`() { | ||
| assertEquals(0, sut.getSentryExceptions(null).size) | ||
| } | ||
|
|
||
| @Test | ||
| fun `when getSentryExceptions is called passing an Exception, it should set its fields`() { | ||
| val exception = Exception("Exception") | ||
| val sentryExceptions = sut.getSentryExceptions(exception) | ||
| assertEquals("Exception", sentryExceptions[0].type) | ||
| assertEquals("Exception", sentryExceptions[0].value) | ||
| assertEquals("java.lang", sentryExceptions[0].module) | ||
| assertTrue(sentryExceptions[0].stacktrace.frames.size > 0) | ||
| } | ||
|
|
||
| @Test | ||
| fun `when getSentryExceptions is called passing a ExceptionMechanism, it should set its fields`() { | ||
| val mechanism = Mechanism() | ||
| mechanism.type = "anr" | ||
| mechanism.handled = false | ||
|
|
||
| val error = Exception("Exception") | ||
|
|
||
| val throwable = ExceptionMechanismThrowable(mechanism, error) | ||
|
|
||
| val sentryExceptions = sut.getSentryExceptions(throwable) | ||
| assertEquals("anr", sentryExceptions[0].mechanism.type) | ||
| assertEquals(false, sentryExceptions[0].mechanism.handled) | ||
| } | ||
|
|
||
| @Test | ||
| fun `when exception has a cause, ensure conversion queue keeps order`() { | ||
| val exception = Exception("message", Exception("cause")) | ||
| val queue = sut.extractExceptionQueue(exception) | ||
|
|
||
| assertEquals("message", queue.first.value) | ||
| assertEquals("cause", queue.last.value) | ||
| } | ||
|
|
||
| @Test | ||
| fun `when getSentryExceptions is called passing an Inner exception, not empty result`() { | ||
| val exception = InnerClassThrowable(InnerClassThrowable()) | ||
| val queue = sut.extractExceptionQueue(exception) | ||
| assertEquals("SentryExceptionFactoryTest\$InnerClassThrowable", queue.first.type) | ||
| } | ||
|
|
||
| private inner class InnerClassThrowable constructor(cause: Throwable? = null) : Throwable(cause) | ||
| } |
32 changes: 32 additions & 0 deletions
32
sentry-core/src/test/java/io/sentry/core/SentryStackTraceFactoryTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package io.sentry.core | ||
|
|
||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertTrue | ||
|
|
||
| class SentryStackTraceFactoryTest { | ||
| private val sut = SentryStackTraceFactory() | ||
|
|
||
| @Test | ||
| fun `when getStackFrames is called passing a valid Array, not empty result`() { | ||
| val stacktraces = Thread.currentThread().stackTrace | ||
| assertTrue(sut.getStackFrames(stacktraces).count() > 0) | ||
| } | ||
|
|
||
| @Test | ||
| fun `when getStackFrames is called passing null, empty result`() { | ||
| assertEquals(0, sut.getStackFrames(null).count()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `when getStackFrames is called passing a valid array, fields should be set`() { | ||
| val element = StackTraceElement("class", "method", "fileName", -2) | ||
| val stacktraces = Array(1) { element } | ||
| val stackFrames = sut.getStackFrames(stacktraces) | ||
| assertEquals("class", stackFrames[0].module) | ||
| assertEquals("method", stackFrames[0].function) | ||
| assertEquals("fileName", stackFrames[0].filename) | ||
| assertEquals(-2, stackFrames[0].lineno) | ||
| assertEquals(true, stackFrames[0].isNative) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.