use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project mobile-center-sdk-android by Microsoft.
the class ErrorLogHelper method getModelExceptionFromThrowable.
@NonNull
public static Exception getModelExceptionFromThrowable(@NonNull Throwable t) {
Exception topException = null;
Exception parentException = null;
List<Throwable> causeChain = new LinkedList<>();
for (Throwable cause = t; cause != null; cause = cause.getCause()) {
causeChain.add(cause);
}
if (causeChain.size() > CAUSE_LIMIT) {
AppCenterLog.warn(Crashes.LOG_TAG, "Crash causes truncated from " + causeChain.size() + " to " + CAUSE_LIMIT + " causes.");
causeChain.subList(CAUSE_LIMIT_HALF, causeChain.size() - CAUSE_LIMIT_HALF).clear();
}
for (Throwable cause : causeChain) {
Exception exception = new Exception();
exception.setType(cause.getClass().getName());
exception.setMessage(cause.getMessage());
exception.setFrames(getModelFramesFromStackTrace(cause));
if (topException == null) {
topException = exception;
} else {
parentException.setInnerExceptions(Collections.singletonList(exception));
}
parentException = exception;
}
// noinspection ConstantConditions
return topException;
}
use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project mobile-center-sdk-android by Microsoft.
the class ErrorLogHelperTest method truncateCauses.
@Test
public void truncateCauses() {
RuntimeException e = new RuntimeException();
for (int i = 0; i < 32; i++) {
e = new RuntimeException(Integer.valueOf(i).toString(), e);
}
int depth = 1;
Exception model = ErrorLogHelper.getModelExceptionFromThrowable(e);
while (model.getInnerExceptions() != null && (model = model.getInnerExceptions().get(0)) != null) {
depth++;
}
assertEquals(ErrorLogHelper.CAUSE_LIMIT, depth);
}
use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project appcenter-sdk-android by microsoft.
the class ErrorLogHelperTest method truncateCauses.
@Test
public void truncateCauses() {
RuntimeException e = new RuntimeException();
for (int i = 0; i < 32; i++) {
e = new RuntimeException(Integer.valueOf(i).toString(), e);
}
int depth = 1;
Exception model = ErrorLogHelper.getModelExceptionFromThrowable(e);
while (model.getInnerExceptions() != null && (model = model.getInnerExceptions().get(0)) != null) {
depth++;
}
assertEquals(ErrorLogHelper.CAUSE_LIMIT, depth);
}
use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project appcenter-sdk-android by microsoft.
the class HandledErrorTest method trackExceptionWithOneAttachmentFromWrapper.
@Test
public void trackExceptionWithOneAttachmentFromWrapper() {
/* If we start crashes. */
startCrashes();
/* When we track error with an attachment. */
ErrorAttachmentLog textAttachment = ErrorAttachmentLog.attachmentWithText("text", null);
Exception exception = new Exception();
String errorId = WrapperSdkExceptionManager.trackException(exception, null, Collections.singleton(textAttachment));
assertNotNull(errorId);
/* Then we send the handled error. */
ArgumentCaptor<Log> log = ArgumentCaptor.forClass(Log.class);
verify(mChannel, times(2)).enqueue(log.capture(), eq(mCrashes.getGroupName()), eq(DEFAULTS));
assertNotNull(log.getAllValues());
assertEquals(2, log.getAllValues().size());
assertTrue(log.getAllValues().get(0) instanceof HandledErrorLog);
HandledErrorLog handledErrorLog = (HandledErrorLog) log.getAllValues().get(0);
assertEquals(exception, handledErrorLog.getException());
assertEquals(errorId, String.valueOf(handledErrorLog.getId()));
/* Then the attachment. */
assertSame(textAttachment, log.getAllValues().get(1));
}
use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project appcenter-sdk-android by microsoft.
the class WrapperSdkExceptionManagerTest method saveWrapperSdkCrashFailsWithIOExceptionAfterLog.
@Test
public void saveWrapperSdkCrashFailsWithIOExceptionAfterLog() throws IOException, JSONException {
String data = "d";
doThrow(new IOException()).when(FileManager.class);
FileManager.write(any(File.class), eq(data));
LogSerializer logSerializer = Mockito.mock(LogSerializer.class);
when(logSerializer.serializeLog(any(ManagedErrorLog.class))).thenReturn("mock");
Crashes.getInstance().setLogSerializer(logSerializer);
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
verifyStatic();
AppCenterLog.error(anyString(), anyString(), argThat(new ArgumentMatcher<Throwable>() {
@Override
public boolean matches(Object argument) {
return argument instanceof IOException;
}
}));
/* Second call is ignored. */
data = "e";
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
/* No more error. */
verifyStatic();
AppCenterLog.error(anyString(), anyString(), argThat(new ArgumentMatcher<Throwable>() {
@Override
public boolean matches(Object argument) {
return argument instanceof IOException;
}
}));
}
Aggregations