Propagate agent errors to Sparkle

This commit is contained in:
Zorg committed 2021-02-28 22:14:35 -08:00
1 parent 1526a024b8
commit f43b5ee3c3
8 files changed
+51 -16

No files matched your search

+1
View File
@@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly, nullable) id<SPUInstallerAgentProtocol> agent;
@property (nonatomic, readonly) BOOL connected;
@property (nonatomic, nullable) NSError *invalidationError;
@end
+7
View File
@@ -105,4 +105,11 @@
acknowledgement();
}
- (void)connectionWillInvalidateWithError:(NSError *)error
{
dispatch_async(dispatch_get_main_queue(), ^{
self.invalidationError = error;
});
}
@end
+8 -1
View File
@@ -279,7 +279,14 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
- (void)agentConnectionDidInvalidate
{
if (!self.finishedValidation || !self.agentInitiatedConnection) {
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Agent connection invalidated before installation began" }]];
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ NSLocalizedDescriptionKey: @"Error: Agent connection invalidated before installation began" }];
NSError *agentError = self.agentConnection.invalidationError;
if (agentError != nil) {
userInfo[NSUnderlyingErrorKey] = agentError;
}
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:userInfo]];
}
}
+5
View File
@@ -38,6 +38,11 @@ typedef NS_ENUM(int32_t, SPUUpdaterMessageType)
SPUUpdaterAlivePong = 3
};
typedef NS_ENUM(int32_t, SPUAgentMessageType)
{
SPUAgentError = 100
};
BOOL SPUInstallerMessageTypeIsLegal(SPUInstallerMessageType oldMessageType, SPUInstallerMessageType newMessageType);
NSString *SPUInstallerServiceNameForBundleIdentifier(NSString *bundleIdentifier);
+1 -1
View File
@@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)run;
- (void)cleanupAndExitWithStatus:(int)status __attribute__((noreturn));
- (void)cleanupAndExitWithStatus:(int)status error:(NSError * _Nullable)error __attribute__((noreturn));
@end
+26 -13
View File
@@ -15,6 +15,7 @@
#import "SUInstallerAgentInitiationProtocol.h"
#import "StatusInfo.h"
#import "SUHost.h"
#import "SUErrors.h"
/*!
* Terminate the application after a delay from launching the new update to avoid OS activation issues
@@ -61,25 +62,25 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
if (self != nil) {
if (arguments.count != 3) {
SULog(SULogLevelError, @"Error: Invalid number of arguments supplied: %@", arguments);
[self cleanupAndExitWithStatus:EXIT_FAILURE];
[self cleanupAndExitWithStatus:EXIT_FAILURE error:nil];
}
NSString *hostBundlePath = arguments[1];
if (hostBundlePath.length == 0) {
SULog(SULogLevelError, @"Error: Host bundle path length is 0");
[self cleanupAndExitWithStatus:EXIT_FAILURE];
[self cleanupAndExitWithStatus:EXIT_FAILURE error:nil];
}
_hostBundle = [NSBundle bundleWithPath:hostBundlePath];
if (_hostBundle == nil) {
SULog(SULogLevelError, @"Error: Host bundle for target is nil");
[self cleanupAndExitWithStatus:EXIT_FAILURE];
[self cleanupAndExitWithStatus:EXIT_FAILURE error:nil];
}
NSString *hostBundleIdentifier = _hostBundle.bundleIdentifier;
if (hostBundleIdentifier == nil) {
SULog(SULogLevelError, @"Error: Host bundle identifier for target is nil");
[self cleanupAndExitWithStatus:EXIT_FAILURE];
[self cleanupAndExitWithStatus:EXIT_FAILURE error:nil];
return nil; // just to silence analyzer warnings later about hostBundleIdentifier being nil
}
@@ -112,11 +113,14 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
InstallerProgressAppController *strongSelf = weakSelf;
if (strongSelf != nil) {
int exitStatus = (strongSelf.repliedToRegistration ? EXIT_SUCCESS : EXIT_FAILURE);
NSError *registrationError;
if (!strongSelf.repliedToRegistration) {
SULog(SULogLevelError, @"Error: Agent Invalidating without having the chance to reply to installer");
registrationError = [NSError errorWithDomain:SUSparkleErrorDomain code:SPUAgentError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Agent Invalidating without having the chance to reply to installer" }];
} else {
registrationError = nil;
}
if (!strongSelf.willTerminate) {
[strongSelf cleanupAndExitWithStatus:exitStatus];
[strongSelf cleanupAndExitWithStatus:exitStatus error:registrationError];
}
}
});
@@ -144,7 +148,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(CONNECTION_ACKNOWLEDGEMENT_TIMEOUT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (!self.connected) {
SULog(SULogLevelError, @"Timeout error: failed to receive acknowledgement from installer");
[self cleanupAndExitWithStatus:EXIT_FAILURE];
[self cleanupAndExitWithStatus:EXIT_FAILURE error:nil];
}
});
}
@@ -154,8 +158,19 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
[self startConnection];
}
- (void)cleanupAndExitWithStatus:(int)status __attribute__((noreturn))
- (void)cleanupAndExitWithStatus:(int)status error:(NSError * _Nullable)error __attribute__((noreturn))
{
if (error != nil) {
SULog(SULogLevelError, @"Agent failed with error: %@", error);
NSError *underlyingError = error.userInfo[NSUnderlyingErrorKey];
if (underlyingError != nil) {
SULog(SULogLevelError, @"Error: %@", underlyingError);
}
[(id<SUInstallerAgentInitiationProtocol>)self.connection.remoteObjectProxy connectionWillInvalidateWithError:error];
}
[self.statusInfo invalidate];
[self.connection invalidate];
@@ -200,8 +215,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
if (applicationBundlePath != nil && !self.willTerminate) {
NSBundle *applicationBundle = [NSBundle bundleWithPath:applicationBundlePath];
if (applicationBundle == nil) {
SULog(SULogLevelError, @"Error: Encountered invalid path for waiting termination: %@", applicationBundlePath);
[self cleanupAndExitWithStatus:EXIT_FAILURE];
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUAgentError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Encountered invalid path for waiting termination: %@", applicationBundlePath] }]];
}
NSArray<NSRunningApplication *> *runningApplications = [self runningApplicationsWithBundle:applicationBundle];
@@ -261,8 +275,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
// We should at least make sure we're opening a bundle however
NSBundle *relaunchBundle = [NSBundle bundleWithPath:pathToRelaunch];
if (relaunchBundle == nil) {
SULog(SULogLevelError, @"Error: Encountered invalid path to relaunch: %@", pathToRelaunch);
[self cleanupAndExitWithStatus:EXIT_FAILURE];
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUAgentError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Encountered invalid path to relaunch: %@", pathToRelaunch] }]];
}
// We only launch applications, but I'm not sure how reliable -launchApplicationAtURL:options:config: is so we're not using it
@@ -276,7 +289,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
self.willTerminate = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SUTerminationTimeDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self cleanupAndExitWithStatus:EXIT_SUCCESS];
[self cleanupAndExitWithStatus:EXIT_SUCCESS error:nil];
});
}
});
@@ -12,4 +12,6 @@
- (void)connectionDidInitiateWithReply:(void (^)(void))acknowledgement;
- (void)connectionWillInvalidateWithError:(NSError *)error;
@end
+1 -1
View File
@@ -27,7 +27,7 @@ int main(int __unused argc, const char __unused *argv[])
dispatch_source_t sigtermSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM, 0, dispatch_get_main_queue());
dispatch_source_set_event_handler(sigtermSource, ^{
[appController cleanupAndExitWithStatus:SIGTERM];
[appController cleanupAndExitWithStatus:SIGTERM error:nil];
});
dispatch_resume(sigtermSource);