-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4e6744
commit e56cf47
Showing
29 changed files
with
56 additions
and
293 deletions.
There are no files selected for viewing
This file contains 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
52 changes: 22 additions & 30 deletions
52
...ntegrationTest/kotlin/io/embrace/android/embracesdk/assertions/InternalErrorAssertions.kt
This file contains 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 |
---|---|---|
@@ -1,43 +1,35 @@ | ||
package io.embrace.android.embracesdk.assertions | ||
|
||
import io.embrace.android.embracesdk.payload.LegacyExceptionError | ||
import io.embrace.android.embracesdk.IntegrationTestRule | ||
import org.junit.Assert.assertTrue | ||
import io.embrace.android.embracesdk.FakeDeliveryService | ||
import io.embrace.android.embracesdk.findLogAttribute | ||
import io.embrace.android.embracesdk.injection.ModuleInitBootstrapper | ||
import org.junit.Assert.fail | ||
|
||
/** | ||
* Return true if at least one exception matching the expected time, exception type, and error message is found in the internal errors | ||
*/ | ||
internal fun assertInternalErrorLogged( | ||
exceptionError: LegacyExceptionError?, | ||
bootstrapper: ModuleInitBootstrapper, | ||
exceptionClassName: String, | ||
errorMessage: String, | ||
errorTimeMs: Long = IntegrationTestRule.DEFAULT_SDK_START_TIME_MS | ||
errorMessage: String | ||
) { | ||
requireNotNull(exceptionError) { "No internal errors found" } | ||
var foundErrorMatch = false | ||
var foundErrorAtTime = false | ||
val unmatchedDetails: MutableList<String> = mutableListOf() | ||
val errors = exceptionError.exceptionErrors.toList() | ||
assertTrue("No exception errors found", errors.isNotEmpty()) | ||
errors.forEach { error -> | ||
if (errorTimeMs == error.timestamp) { | ||
foundErrorAtTime = true | ||
val firstExceptionInfo = checkNotNull(error.exceptions).first() | ||
with(firstExceptionInfo) { | ||
if (exceptionClassName == name && errorMessage == message) { | ||
foundErrorMatch = true | ||
} else { | ||
unmatchedDetails.add("'$exceptionClassName' is not '$name' OR '$errorMessage' is not '$message' \n") | ||
} | ||
} | ||
bootstrapper.customerLogModule.logOrchestrator.flush(false) | ||
val deliveryService = bootstrapper.deliveryModule.deliveryService as FakeDeliveryService | ||
val logs = deliveryService.lastSentLogPayloads.mapNotNull { it.data.logs } | ||
.flatten() | ||
.filter { log -> | ||
log.findLogAttribute("emb.type") == "sys.internal" | ||
} | ||
} | ||
|
||
assertTrue("No internal error found matching the expected time", foundErrorAtTime) | ||
if (logs.isEmpty()) { | ||
fail("No internal errors found") | ||
} | ||
|
||
assertTrue( | ||
"Expected exception not found. " + | ||
"Found following ${unmatchedDetails.size} exceptions in ${errors.size} errors instead: $unmatchedDetails", | ||
foundErrorMatch | ||
) | ||
val matchingLogs = logs.filter { log -> | ||
log.findLogAttribute("exception.type") == exceptionClassName && | ||
log.findLogAttribute("exception.message") == errorMessage | ||
} | ||
if (matchingLogs.isEmpty()) { | ||
fail("No internal errors found matching the expected exception") | ||
} | ||
} |
This file contains 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 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
29 changes: 4 additions & 25 deletions
29
...java/io/embrace/android/embracesdk/capture/internal/errors/EmbraceInternalErrorService.kt
This file contains 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 |
---|---|---|
@@ -1,36 +1,15 @@ | ||
package io.embrace.android.embracesdk.capture.internal.errors | ||
|
||
import io.embrace.android.embracesdk.config.ConfigService | ||
import io.embrace.android.embracesdk.internal.clock.Clock | ||
import io.embrace.android.embracesdk.payload.LegacyExceptionError | ||
import io.embrace.android.embracesdk.internal.utils.Provider | ||
|
||
/** | ||
* Intercepts Embrace SDK's exceptions errors and forwards them to the Embrace API. | ||
*/ | ||
internal class EmbraceInternalErrorService( | ||
private val clock: Clock | ||
) : InternalErrorService { | ||
|
||
private var err: LegacyExceptionError = LegacyExceptionError() | ||
internal class EmbraceInternalErrorService : InternalErrorService { | ||
|
||
override fun handleInternalError(throwable: Throwable) { | ||
// if the config service has not been set yet, capture the exception | ||
if (configService == null || configService?.dataCaptureEventBehavior?.isInternalExceptionCaptureEnabled() == true) { | ||
err.addException( | ||
throwable, | ||
clock | ||
) | ||
} | ||
internalErrorDataSource()?.handleInternalError(throwable) | ||
} | ||
|
||
override var configService: ConfigService? = null | ||
|
||
override fun getCapturedData(): LegacyExceptionError? = when { | ||
err.occurrences > 0 -> err | ||
else -> null | ||
} | ||
|
||
override fun cleanCollections() { | ||
err = LegacyExceptionError() | ||
} | ||
override var internalErrorDataSource: Provider<InternalErrorDataSource?> = { null } | ||
} |
8 changes: 3 additions & 5 deletions
8
...c/main/java/io/embrace/android/embracesdk/capture/internal/errors/InternalErrorService.kt
This file contains 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 |
---|---|---|
@@ -1,13 +1,11 @@ | ||
package io.embrace.android.embracesdk.capture.internal.errors | ||
|
||
import io.embrace.android.embracesdk.arch.DataCaptureService | ||
import io.embrace.android.embracesdk.config.ConfigService | ||
import io.embrace.android.embracesdk.payload.LegacyExceptionError | ||
import io.embrace.android.embracesdk.internal.utils.Provider | ||
|
||
/** | ||
* Reports an internal error to Embrace. An internal error is defined as an exception that was | ||
* caught within Embrace code & logged to [EmbLogger]. | ||
*/ | ||
internal interface InternalErrorService : DataCaptureService<LegacyExceptionError?>, InternalErrorHandler { | ||
var configService: ConfigService? | ||
internal interface InternalErrorService : InternalErrorHandler { | ||
var internalErrorDataSource: Provider<InternalErrorDataSource?> | ||
} |
This file contains 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 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 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 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 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 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 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 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 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 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 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
Oops, something went wrong.