use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project appcenter-sdk-android by microsoft.
the class WrapperSdkExceptionManagerTest method saveWrapperSdkCrashFailsWithJSONException.
@Test
public void saveWrapperSdkCrashFailsWithJSONException() throws JSONException {
LogSerializer logSerializer = Mockito.mock(LogSerializer.class);
when(logSerializer.serializeLog(any(ManagedErrorLog.class))).thenThrow(new JSONException("mock"));
Crashes.getInstance().setLogSerializer(logSerializer);
String data = "d";
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 JSONException;
}
}));
/* 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 JSONException;
}
}));
}
use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project appcenter-sdk-android by microsoft.
the class WrapperSdkExceptionManagerTest method saveWrapperSdkCrash.
@Test
public void saveWrapperSdkCrash() throws JSONException, IOException {
LogSerializer logSerializer = Mockito.mock(LogSerializer.class);
when(logSerializer.serializeLog(any(ManagedErrorLog.class))).thenReturn("mock");
Crashes.getInstance().setLogSerializer(logSerializer);
String data = "d";
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
verifyStatic();
FileManager.write(any(File.class), eq(data));
/* We can't do it twice in the same process. */
data = "e";
WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), data);
verifyStatic(never());
FileManager.write(any(File.class), eq(data));
}
use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project appcenter-sdk-android by microsoft.
the class Crashes method processSingleMinidump.
/**
* Process the minidump, save an error log with a reference to the minidump, move the minidump file to the 'pending' folder.
*
* @param minidumpFile a file where an ndk crash is saved.
* @param minidumpFolder a folder that contains device info and a minidump file.
*/
private void processSingleMinidump(File minidumpFile, File minidumpFolder) {
/* Create missing files from the native crash that we detected. */
AppCenterLog.debug(LOG_TAG, "Process pending minidump file: " + minidumpFile);
long minidumpDate = minidumpFile.lastModified();
File dest = new File(ErrorLogHelper.getPendingMinidumpDirectory(), minidumpFile.getName());
Exception modelException = new Exception();
modelException.setType("minidump");
modelException.setWrapperSdkName(WRAPPER_SDK_NAME_NDK);
modelException.setMinidumpFilePath(dest.getPath());
ManagedErrorLog errorLog = new ManagedErrorLog();
errorLog.setException(modelException);
errorLog.setTimestamp(new Date(minidumpDate));
errorLog.setFatal(true);
errorLog.setId(ErrorLogHelper.parseLogFolderUuid(minidumpFolder));
/* Lookup app launch timestamp in session history. */
SessionContext.SessionInfo session = SessionContext.getInstance().getSessionAt(minidumpDate);
if (session != null && session.getAppLaunchTimestamp() <= minidumpDate) {
errorLog.setAppLaunchTimestamp(new Date(session.getAppLaunchTimestamp()));
} else {
/*
* Fall back to log date if app launch timestamp information lost
* or in the future compared to crash time.
* This also covers the case where app launches then crashes within 1s:
* app launch timestamp would have ms accuracy while minidump file is without
* ms, in that case we also falls back to log timestamp
* (this would be same result as truncating ms).
*/
errorLog.setAppLaunchTimestamp(errorLog.getTimestamp());
}
/*
* TODO The following properties are placeholders because fields are required.
* They should be removed from schema as not used by server.
*/
errorLog.setProcessId(0);
errorLog.setProcessName("");
try {
String savedUserId = ErrorLogHelper.getStoredUserInfo(minidumpFolder);
Device savedDeviceInfo = ErrorLogHelper.getStoredDeviceInfo(minidumpFolder);
if (savedDeviceInfo == null) {
/*
* Fallback to use device info from the current launch.
* It may lead to an incorrect app version being reported.
*/
savedDeviceInfo = getDeviceInfo(mContext);
savedDeviceInfo.setWrapperSdkName(WRAPPER_SDK_NAME_NDK);
}
errorLog.setDevice(savedDeviceInfo);
errorLog.setUserId(savedUserId);
saveErrorLogFiles(new NativeException(), errorLog);
if (!minidumpFile.renameTo(dest)) {
throw new IOException("Failed to move file");
}
} catch (java.lang.Exception e) {
// noinspection ResultOfMethodCallIgnored
minidumpFile.delete();
removeAllStoredErrorLogFiles(errorLog.getId());
AppCenterLog.error(LOG_TAG, "Failed to process new minidump file: " + minidumpFile, e);
}
}
use of com.microsoft.appcenter.crashes.ingestion.models.Exception in project appcenter-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;
}
Aggregations