@@ -6,8 +6,8 @@ import os
6
6
@MainActor
7
7
public protocol FileSyncDaemon : ObservableObject {
8
8
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 )
11
11
}
12
12
13
13
@MainActor
@@ -47,7 +47,7 @@ public class MutagenDaemon: FileSyncDaemon {
47
47
}
48
48
}
49
49
50
- public func start( ) async throws {
50
+ public func start( ) async throws ( DaemonError ) {
51
51
if case . unavailable = state { return }
52
52
53
53
// Stop an orphaned daemon, if there is one
@@ -59,16 +59,21 @@ public class MutagenDaemon: FileSyncDaemon {
59
59
try mutagenProcess? . run ( )
60
60
} catch {
61
61
state = . failed( " Failed to start file sync daemon: \( error) " )
62
- throw MutagenDaemonError . daemonStartFailure ( error)
62
+ throw DaemonError . daemonStartFailure ( error)
63
63
}
64
64
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
+ }
66
71
67
72
state = . running
68
- logger. info ( " mutagen daemon started " )
73
+ logger. info ( " mutagen daemon started, pid: \( self . mutagenProcess ? . processIdentifier . description ?? " unknown " ) " )
69
74
}
70
75
71
- private func connect( ) async throws {
76
+ private func connect( ) async throws ( DaemonError ) {
72
77
guard client == nil else {
73
78
// Already connected
74
79
return
@@ -86,8 +91,8 @@ public class MutagenDaemon: FileSyncDaemon {
86
91
)
87
92
} catch {
88
93
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)
91
96
}
92
97
}
93
98
@@ -100,7 +105,7 @@ public class MutagenDaemon: FileSyncDaemon {
100
105
group = nil
101
106
}
102
107
103
- public func stop( ) async throws {
108
+ public func stop( ) async throws ( DaemonError ) {
104
109
if case . unavailable = state { return }
105
110
state = . stopped
106
111
guard FileManager . default. fileExists ( atPath: mutagenDaemonSocket. path) else {
@@ -169,7 +174,7 @@ public enum DaemonState {
169
174
case unavailable
170
175
}
171
176
172
- public enum MutagenDaemonError : Error {
177
+ public enum DaemonError : Error {
173
178
case daemonStartFailure( Error )
174
179
case connectionFailure( Error )
175
180
}
0 commit comments