Merge remote-tracking branch 'origin/feature/improve-crash-error-handling' into release/HockeySDK-iOS-4.0.2

This commit is contained in:
Benjamin Reimold
2016-07-15 13:55:08 -07:00
2 changed files with 26 additions and 10 deletions

View File

@@ -213,10 +213,6 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
_settingsFile = [_crashesDir stringByAppendingPathComponent:BITHOCKEY_CRASH_SETTINGS];
_analyzerInProgressFile = [_crashesDir stringByAppendingPathComponent:BITHOCKEY_CRASH_ANALYZER];
if ([_fileManager fileExistsAtPath:_analyzerInProgressFile]) {
NSError *error = nil;
[_fileManager removeItemAtPath:_analyzerInProgressFile error:&error];
}
if (!BITHockeyBundle() && !bit_isRunningInAppExtension()) {
NSLog(@"[HockeySDK] WARNING: %@ is missing, will send reports automatically!", BITHOCKEYSDK_BUNDLE);
@@ -327,7 +323,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
}
}
- (void)persistAttachment:(BITHockeyAttachment *)attachment withFilename:(NSString *)filename {
- (BOOL)persistAttachment:(BITHockeyAttachment *)attachment withFilename:(NSString *)filename {
NSString *attachmentFilename = [filename stringByAppendingString:@".data"];
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
@@ -336,7 +332,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
[archiver finishEncoding];
[data writeToFile:attachmentFilename atomically:YES];
return [data writeToFile:attachmentFilename atomically:YES];
}
- (void)persistUserProvidedMetaData:(BITCrashMetaData *)userProvidedMetaData {
@@ -737,6 +733,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
* @param filename the crash reports temp filename
*/
- (void)storeMetaDataForCrashReportFilename:(NSString *)filename {
BITHockeyLog(@"VERBOSE: Storing meta data for crash report with filename %@", filename);
NSError *error = NULL;
NSMutableDictionary *metaDict = [NSMutableDictionary dictionaryWithCapacity:4];
NSString *applicationLog = @"";
@@ -751,10 +748,18 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
[metaDict setObject:applicationLog forKey:kBITCrashMetaApplicationLog];
if ([self.delegate respondsToSelector:@selector(attachmentForCrashManager:)]) {
BITHockeyLog(@"VERBOSE: Processing attachment for crash report with filename %@", filename);
BITHockeyAttachment *attachment = [self.delegate attachmentForCrashManager:self];
if (attachment && attachment.hockeyAttachmentData) {
[self persistAttachment:attachment withFilename:[_crashesDir stringByAppendingPathComponent: filename]];
BOOL success = [self persistAttachment:attachment withFilename:[_crashesDir stringByAppendingPathComponent: filename]];
if (!success) {
BITHockeyLog(@"ERROR: Persisting the crash attachment failed");
} else {
BITHockeyLog(@"VERBOSE: Crash attachment successfully persisted.");
}
} else {
BITHockeyLog(@"INFO: Crash attachment was nil");
}
}
@@ -763,10 +768,14 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
options:0
error:&error];
if (plist) {
[plist writeToFile:[_crashesDir stringByAppendingPathComponent: [filename stringByAppendingPathExtension:@"meta"]] atomically:YES];
BOOL success = [plist writeToFile:[_crashesDir stringByAppendingPathComponent: [filename stringByAppendingPathExtension:@"meta"]] atomically:YES];
if (!success) {
BITHockeyLog(@"ERROR: Writing crash meta data failed.");
}
} else {
BITHockeyLog(@"ERROR: Writing crash meta data failed. %@", error);
BITHockeyLog(@"ERROR: Serializing metaDict failed. %@", error);
}
BITHockeyLog(@"VERBOSE: Storing crash meta data finished.");
}
- (BOOL)handleUserInput:(BITCrashManagerUserInput)userInput withUserProvidedMetaData:(BITCrashMetaData *)userProvidedMetaData {
@@ -817,6 +826,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
* Parse the new crash report and gather additional meta data from the app which will be stored along the crash report
*/
- (void) handleCrashReport {
BITHockeyLog(@"VERBOSE: Handling crash report");
NSError *error = NULL;
if (!self.plCrashReporter) return;
@@ -825,6 +835,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
if (![_fileManager fileExistsAtPath:_analyzerInProgressFile]) {
// mark the start of the routine
[_fileManager createFileAtPath:_analyzerInProgressFile contents:nil attributes:nil];
BITHockeyLog(@"VERBOSE: AnalyzerInProgress file created");
[self saveSettings];
@@ -880,6 +891,8 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
[self storeMetaDataForCrashReportFilename:cacheFilename];
}
}
} else {
BITHockeyLog(@"WARNING: AnalyzerInProgress file found, handling crash report skipped");
}
// Purge the report
@@ -968,6 +981,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
}
- (void)triggerDelayedProcessing {
BITHockeyLog(@"VERBOE: Triggering delayed crash processing.");
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(invokeDelayedProcessing) object:nil];
[self performSelector:@selector(invokeDelayedProcessing) withObject:nil afterDelay:0.5];
}
@@ -1222,6 +1236,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
}
if (considerReport) {
BITHockeyLog(@"INFO: App kill detected, creating crash report.");
[self createCrashReportForAppKill];
_didCrashInLastSession = YES;
@@ -1241,6 +1256,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf
[[NSUserDefaults standardUserDefaults] synchronize];
[self triggerDelayedProcessing];
BITHockeyLog(@"VERBOSE: CrashManager startManager has finished.");
}
/**

View File

@@ -94,7 +94,7 @@
- (NSString *)firstNotApprovedCrashReport;
- (void)persistUserProvidedMetaData:(BITCrashMetaData *)userProvidedMetaData;
- (void)persistAttachment:(BITHockeyAttachment *)attachment withFilename:(NSString *)filename;
- (BOOL)persistAttachment:(BITHockeyAttachment *)attachment withFilename:(NSString *)filename;
- (BITHockeyAttachment *)attachmentForCrashReport:(NSString *)filename;