@@ -6,8 +6,8 @@ import os
66@MainActor
77public protocol FileSyncDaemon : ObservableObject {
88 var state : DaemonState { get }
9- func start( ) async throws
10- func stop( ) async throws
9+ func start( ) async throws ( DaemonError )
10+ func stop( ) async throws ( DaemonError )
1111}
1212
1313@MainActor
@@ -47,7 +47,7 @@ public class MutagenDaemon: FileSyncDaemon {
4747 }
4848 }
4949
50- public func start( ) async throws {
50+ public func start( ) async throws ( DaemonError ) {
5151 if case . unavailable = state { return }
5252
5353 // Stop an orphaned daemon, if there is one
@@ -59,16 +59,21 @@ public class MutagenDaemon: FileSyncDaemon {
5959 try mutagenProcess? . run ( )
6060 } catch {
6161 state = . failed( " Failed to start file sync daemon: \( error) " )
62- throw MutagenDaemonError . daemonStartFailure ( error)
62+ throw DaemonError . daemonStartFailure ( error)
6363 }
6464
65- try await connect ( )
65+ do {
66+ try await connect ( )
67+ } catch {
68+ state = . failed( " failed to connect to file sync daemon: \( error) " )
69+ throw DaemonError . daemonStartFailure ( error)
70+ }
6671
6772 state = . running
68- logger. info ( " mutagen daemon started " )
73+ logger. info ( " mutagen daemon started, pid: \( self . mutagenProcess ? . processIdentifier . description ?? " unknown " ) " )
6974 }
7075
71- private func connect( ) async throws {
76+ private func connect( ) async throws ( DaemonError ) {
7277 guard client == nil else {
7378 // Already connected
7479 return
@@ -86,8 +91,8 @@ public class MutagenDaemon: FileSyncDaemon {
8691 )
8792 } catch {
8893 logger. error ( " Failed to connect to gRPC: \( error) " )
89- try await cleanupGRPC ( )
90- throw MutagenDaemonError . connectionFailure ( error)
94+ try ? await cleanupGRPC ( )
95+ throw DaemonError . connectionFailure ( error)
9196 }
9297 }
9398
@@ -100,7 +105,7 @@ public class MutagenDaemon: FileSyncDaemon {
100105 group = nil
101106 }
102107
103- public func stop( ) async throws {
108+ public func stop( ) async throws ( DaemonError ) {
104109 if case . unavailable = state { return }
105110 state = . stopped
106111 guard FileManager . default. fileExists ( atPath: mutagenDaemonSocket. path) else {
@@ -169,7 +174,7 @@ public enum DaemonState {
169174 case unavailable
170175}
171176
172- public enum MutagenDaemonError : Error {
177+ public enum DaemonError : Error {
173178 case daemonStartFailure( Error )
174179 case connectionFailure( Error )
175180}
0 commit comments