diff --git a/Sparkle/SPUAutomaticUpdateDriver.m b/Sparkle/SPUAutomaticUpdateDriver.m index 43fb5acb..4c58c1d0 100644 --- a/Sparkle/SPUAutomaticUpdateDriver.m +++ b/Sparkle/SPUAutomaticUpdateDriver.m @@ -69,14 +69,12 @@ { // Nothing really to do here.. this shouldn't be called. SULog(SULogLevelError, @"Error: resumeInstallingUpdateWithCompletion: called on SPUAutomaticUpdateDriver"); - abort(); } - (void)resumeUpdate:(id)__unused resumableUpdate completion:(SPUUpdateDriverCompletion)__unused completionBlock __attribute__((noreturn)) { // Nothing really to do here.. this shouldn't be called. SULog(SULogLevelError, @"Error: resumeDownloadedUpdate:completion: called on SPUAutomaticUpdateDriver"); - abort(); } - (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem diff --git a/Sparkle/SPUStandardUpdaterController.m b/Sparkle/SPUStandardUpdaterController.m index 84c4c82b..3a5492f7 100644 --- a/Sparkle/SPUStandardUpdaterController.m +++ b/Sparkle/SPUStandardUpdaterController.m @@ -73,7 +73,15 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults NSError *updaterError = nil; if (![self.updater startUpdater:&updaterError]) { SULog(SULogLevelError, @"Fatal updater error (%ld): %@", updaterError.code, updaterError.localizedDescription); - abort(); + + // Delay the alert four seconds so it doesn't show RIGHT as the app launches, but also doesn't interrupt the user once they really get to work. + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + NSAlert *alert = [[NSAlert alloc] init]; + alert.messageText = @"Unable to Check For Updates"; + alert.informativeText = @"The update checker failed to start correctly. You should contact the app developer to report this issue and verify that you have the latest version."; + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + }); } } diff --git a/Sparkle/SPUUpdater.h b/Sparkle/SPUUpdater.h index 54e3cb3d..14879ff1 100644 --- a/Sparkle/SPUUpdater.h +++ b/Sparkle/SPUUpdater.h @@ -134,9 +134,9 @@ SU_EXPORT @interface SPUUpdater : NSObject If the updater's delegate implements -[SPUUpdaterDelegate feedURLStringForUpdater:], this will return that feed URL. Otherwise if the feed URL has been set before, the feed URL returned will be retrieved from the host bundle's user defaults. Otherwise the feed URL in the host bundle's Info.plist will be returned. - If no feed URL can be retrieved, this will raise an exception. + If no feed URL can be retrieved, returns nil. - This property must be called on the main thread. + This property must be called on the main thread; calls from background threads will return nil. */ @property (nonatomic, readonly) NSURL *feedURL; @@ -149,7 +149,7 @@ SU_EXPORT @interface SPUUpdater : NSObject Passing nil will remove any feed URL that has been set in the host bundle's user defaults. - This method must be called on the main thread. + This method must be called on the main thread; calls from background threads will have no effect. */ - (void)setFeedURL:(NSURL * _Nullable)feedURL; diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index 56d1d7a4..469acd81 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -115,16 +115,24 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification // To prevent subclasses from doing something bad based on older Sparkle code - (instancetype)initForBundle:(NSBundle *)__unused bundle { - SULog(SULogLevelError, @"-[%@ initForBundle:] is not implemented anymore.", NSStringFromClass([self class])); - abort(); + NSString *reason = [NSString stringWithFormat:@"-[%@ initForBundle:] is not implemented anymore in Sparkle 2.", NSStringFromClass([self class])]; + SULog(SULogLevelError, reason); + + NSException *exception = [NSException exceptionWithName:@"SUIncorrectAPIUsageException" reason:reason userInfo:nil]; + @throw exception; + return nil; } // To prevent trying to stick an SUUpdater in a nib or initializing it in an incorrect way - (instancetype)init { - SULog(SULogLevelError, @"-[%@ init] is not implemented. If you want to drop an updater into a nib, see SPUStandardUpdaterController.", NSStringFromClass([self class])); - abort(); + NSString *reason = [NSString stringWithFormat:@"-[%@ init] is not implemented. If you want to drop an updater into a nib, see SPUStandardUpdaterController.", NSStringFromClass([self class])]; + SULog(SULogLevelError, reason); + + NSException *exception = [NSException exceptionWithName:@"SUIncorrectAPIUsageException" reason:reason userInfo:nil]; + @throw exception; + return nil; } @@ -614,8 +622,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification - (void)setFeedURL:(NSURL * _Nullable)feedURL { if (![NSThread isMainThread]) { - SULog(SULogLevelError, @"This method must be called on the main thread"); - abort(); + SULog(SULogLevelError, @"Error: SPUUpdater -setFeedURL: must be called on the main thread. The call from a background thread was ignored."); + return; } // When feedURL is nil, -absoluteString will return nil and will remove the user default key @@ -625,8 +633,11 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification - (BOOL)retrieveFeedURL:(NSURL * __autoreleasing *)feedURL error:(NSError * __autoreleasing *)error { if (![NSThread isMainThread]) { - SULog(SULogLevelError, @"This method must be called on the main thread"); - abort(); + SULog(SULogLevelError, @"Error: SPUUpdater -retrieveFeedURL:error: must be called on the main thread."); + if (error != NULL) { + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUIncorrectAPIUsageError userInfo:@{ NSLocalizedDescriptionKey: @"SUUpdater -retriveFeedURL:error: must be called on the main thread."}]; + } + return NO; } // A value in the user defaults overrides one in the Info.plist (so preferences panels can be created wherein users choose between beta / release feeds). @@ -657,14 +668,14 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification return YES; } -// A client may call this method but do not invoke this method ourselves because its unsafe +// A client may call this method but do not invoke this method ourselves because it's unsafe - (NSURL *)feedURL { NSURL *feedURL = nil; NSError *feedError = nil; if (![self retrieveFeedURL:&feedURL error:&feedError]) { - SULog(SULogLevelError, @"Fatal Feed Error (%ld): %@", feedError.code, feedError.localizedDescription); - abort(); + SULog(SULogLevelError, @"Feed Error (%ld): %@", feedError.code, feedError.localizedDescription); + return nil; } return feedURL; } diff --git a/Sparkle/SUErrors.h b/Sparkle/SUErrors.h index cc6d5785..d42f173d 100644 --- a/Sparkle/SUErrors.h +++ b/Sparkle/SUErrors.h @@ -56,7 +56,10 @@ typedef NS_ENUM(OSStatus, SUError) { SUDowngradeError = 4006, SUInstallationCanceledError = 4007, SUInstallationAuthorizeLaterError = 4008, - SUNotAllowedInteractionError = 4009 + SUNotAllowedInteractionError = 4009, + + // API misuse errors. + SUIncorrectAPIUsageError = 5000 }; #endif diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index c1157ce6..d57e30b6 100755 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -105,7 +105,8 @@ NSString *version = [self _version]; if (version == nil) { SULog(SULogLevelError, @"This host (%@) has no %@! This attribute is required.", [self bundlePath], (__bridge NSString *)kCFBundleVersionKey); - abort(); + // Instead of abort()-ing, return an empty string to satisfy the _Nonnull contract. + return @""; } return version; } diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 66743b58..c382bc3e 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -86,7 +86,6 @@ static NSMutableDictionary *sharedUpdaters = nil; NSError *updaterError = nil; if (![self.updater startUpdater:&updaterError]) { SULog(SULogLevelError, @"Error: Failed to start updater with error: %@", updaterError); - abort(); } }); } diff --git a/TestApplication/SUUpdateSettingsWindowController.m b/TestApplication/SUUpdateSettingsWindowController.m index b96e36f9..2f6047a7 100644 --- a/TestApplication/SUUpdateSettingsWindowController.m +++ b/TestApplication/SUUpdateSettingsWindowController.m @@ -56,7 +56,12 @@ NSError *updaterError = nil; if (![self.updater startUpdater:&updaterError]) { NSLog(@"Failed to start updater with error: %@", updaterError); - abort(); + + NSAlert *alert = [[NSAlert alloc] init]; + alert.messageText = @"Updater Error"; + alert.informativeText = @"The Updater failed to start. For detailed error information, check the Console.app log." + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; } }