From b647a586d3e3aeb54fc80b2ff4b6fa2da9db6636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Spie=C3=9F?= Date: Thu, 7 Jul 2016 17:14:00 +0200 Subject: [PATCH 1/3] Add additional logging in crash processing flow --- Classes/BITCrashManager.m | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Classes/BITCrashManager.m b/Classes/BITCrashManager.m index f22162a3bc..4cae9868bd 100644 --- a/Classes/BITCrashManager.m +++ b/Classes/BITCrashManager.m @@ -737,6 +737,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,6 +752,7 @@ 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) { @@ -765,8 +767,9 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf if (plist) { [plist writeToFile:[_crashesDir stringByAppendingPathComponent: [filename stringByAppendingPathExtension:@"meta"]] atomically:YES]; } 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 +820,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 +829,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 +885,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 +975,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 +1230,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 +1250,7 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf [[NSUserDefaults standardUserDefaults] synchronize]; [self triggerDelayedProcessing]; + BITHockeyLog(@"VERBOSE: CrashManager startManager has finished."); } /** From fa38499602e616d3cf4c3f85f18df43fea67996f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Spie=C3=9F?= Date: Thu, 7 Jul 2016 17:14:41 +0200 Subject: [PATCH 2/3] Add additonal error logging in attachment processing --- Classes/BITCrashManager.m | 18 ++++++++++++++---- Classes/BITCrashManagerPrivate.h | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Classes/BITCrashManager.m b/Classes/BITCrashManager.m index 4cae9868bd..b7567ab829 100644 --- a/Classes/BITCrashManager.m +++ b/Classes/BITCrashManager.m @@ -327,7 +327,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 +336,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 { @@ -756,7 +756,14 @@ static void uncaught_cxx_exception_handler(const BITCrashUncaughtCXXExceptionInf 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"); } } @@ -765,7 +772,10 @@ 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: Serializing metaDict failed. %@", error); } diff --git a/Classes/BITCrashManagerPrivate.h b/Classes/BITCrashManagerPrivate.h index 5bb40500e2..a7f1111842 100644 --- a/Classes/BITCrashManagerPrivate.h +++ b/Classes/BITCrashManagerPrivate.h @@ -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; From 22c40b7e24532a0bb6c20a2c78fbef3e07e7ee64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Spie=C3=9F?= Date: Thu, 7 Jul 2016 17:16:04 +0200 Subject: [PATCH 3/3] Fix analyzerInProgress file always being reset at app start With this line in place, the analyzerInProgress file that is used to detect errors/crashes in previous crash processing is always reset at app start. This prevents proper error detection if crash processing crashes/didn't finish in the previous run. --- Classes/BITCrashManager.m | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Classes/BITCrashManager.m b/Classes/BITCrashManager.m index b7567ab829..3ebdfe444a 100644 --- a/Classes/BITCrashManager.m +++ b/Classes/BITCrashManager.m @@ -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);