Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit678fabd

Browse files
committed
error handling
1 parentffa6e5f commit678fabd

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

‎Coder Desktop/VPNLib/FileSync/FileSyncDaemon.swift

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ import os
66
@MainActor
77
publicprotocolFileSyncDaemon:ObservableObject{
88
varstate:DaemonState{get}
9-
func start()asyncthrows(DaemonError)
10-
func stop()asyncthrows(DaemonError)
9+
func start()async
10+
func stop()async
1111
}
1212

1313
@MainActor
1414
publicclassMutagenDaemon:FileSyncDaemon{
1515
privateletlogger=Logger(subsystem:Bundle.main.bundleIdentifier!, category:"mutagen")
1616

17-
@Publishedpublicvarstate:DaemonState=.stopped
17+
@Publishedpublicvarstate:DaemonState=.stopped{
18+
didSet{
19+
logger.info("daemon state changed:\(self.state.description)")
20+
}
21+
}
1822

1923
privatevarmutagenProcess:Process?
2024
privatevarmutagenPipe:Pipe?
@@ -47,26 +51,24 @@ public class MutagenDaemon: FileSyncDaemon {
4751
}
4852
}
4953

50-
publicfunc start()asyncthrows(DaemonError){
54+
publicfunc start()async{
5155
if case.unavailable= state{return}
5256

5357
// Stop an orphaned daemon, if there is one
5458
try?awaitconnect()
55-
try?awaitstop()
59+
awaitstop()
5660

5761
(mutagenProcess, mutagenPipe)=createMutagenProcess()
5862
do{
5963
try mutagenProcess?.run()
6064
}catch{
61-
state=.failed("Failed to start file sync daemon:\(error)")
62-
throwDaemonError.daemonStartFailure(error)
65+
state=.failed(DaemonError.daemonStartFailure(error))
6366
}
6467

6568
do{
6669
tryawaitconnect()
6770
}catch{
68-
state=.failed("failed to connect to file sync daemon:\(error)")
69-
throwDaemonError.daemonStartFailure(error)
71+
state=.failed(DaemonError.daemonStartFailure(error))
7072
}
7173

7274
state=.running
@@ -105,7 +107,7 @@ public class MutagenDaemon: FileSyncDaemon {
105107
group=nil
106108
}
107109

108-
publicfunc stop()asyncthrows(DaemonError){
110+
publicfunc stop()async{
109111
if case.unavailable= state{return}
110112
state=.stopped
111113
guardFileManager.default.fileExists(atPath: mutagenDaemonSocket.path)else{
@@ -155,7 +157,7 @@ public class MutagenDaemon: FileSyncDaemon {
155157
return
156158
default:
157159
logger.error("mutagen daemon exited unexpectedly")
158-
self.state=.failed("File sync daemon terminated unexpectedly")
160+
self.state=.failed(.terminatedUnexpectedly)
159161
}
160162
}
161163
}
@@ -170,11 +172,38 @@ public class MutagenDaemon: FileSyncDaemon {
170172
publicenumDaemonState{
171173
case running
172174
case stopped
173-
case failed(String)
175+
case failed(DaemonError)
174176
case unavailable
177+
178+
vardescription:String{
179+
switchself{
180+
case.running:
181+
"Running"
182+
case.stopped:
183+
"Stopped"
184+
caselet.failed(error):
185+
"Failed:\(error)"
186+
case.unavailable:
187+
"Unavailable"
188+
}
189+
}
175190
}
176191

177192
publicenumDaemonError:Error{
178193
case daemonStartFailure(Error)
179194
case connectionFailure(Error)
195+
case terminatedUnexpectedly
196+
197+
vardescription:String{
198+
switchself{
199+
caselet.daemonStartFailure(error):
200+
"Daemon start failure:\(error)"
201+
caselet.connectionFailure(error):
202+
"Connection failure:\(error)"
203+
case.terminatedUnexpectedly:
204+
"Daemon terminated unexpectedly"
205+
}
206+
}
207+
208+
varlocalizedDescription:String{ description}
180209
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp