@@ -6,10 +6,10 @@ import TSCUtility
6
6
7
7
public protocol ProgressReporterProtocol {
8
8
/// Updates the progress animation with the current step, total steps, and an optional text message.
9
- func update( step: Int , total: Int , text: String ) async
9
+ func update( step: Int , total: Int , text: String ) async throws
10
10
11
11
/// Completes the progress animation, indicating success or failure.
12
- func complete( success: Bool ) async
12
+ func complete( success: Bool ) async throws
13
13
14
14
/// Closes any resources used by the reporter, if applicable.
15
15
func close( ) throws
@@ -23,15 +23,15 @@ struct ConsoleProgressReporter: ProgressReporterProtocol {
23
23
self . reporter = PercentProgressAnimation ( stream: stream, header: header)
24
24
}
25
25
26
- func update( step: Int , total: Int , text: String ) async {
26
+ func update( step: Int , total: Int , text: String ) async throws {
27
27
self . reporter. update ( step: step, total: total, text: text)
28
28
}
29
29
30
- func complete( success: Bool ) async {
30
+ func complete( success: Bool ) async throws {
31
31
self . reporter. complete ( success: success)
32
32
}
33
33
34
- func close( ) {
34
+ func close( ) throws {
35
35
// No resources to close for console reporter
36
36
}
37
37
}
@@ -55,23 +55,19 @@ struct JsonFileProgressReporter: ProgressReporterProtocol {
55
55
self . fileHandle = try FileHandle ( forWritingTo: URL ( fileURLWithPath: filePath. string) )
56
56
}
57
57
58
- private func writeProgress( _ progress: ProgressInfo ) async {
59
- let jsonData = try ? self . encoder. encode ( progress)
60
- guard let jsonData = jsonData else {
61
- await self . ctx. message ( " Failed to encode progress entry to JSON " )
62
- return
63
- }
58
+ private func writeProgress( _ progress: ProgressInfo ) async throws {
59
+ let jsonData = try self . encoder. encode ( progress)
64
60
65
61
self . fileHandle. write ( jsonData)
66
62
self . fileHandle. write ( " \n " . data ( using: . utf8) ?? Data ( ) )
67
- try ? self . fileHandle. synchronize ( )
63
+ try self . fileHandle. synchronize ( )
68
64
}
69
65
70
- func update( step: Int , total: Int , text: String ) async {
66
+ func update( step: Int , total: Int , text: String ) async throws {
71
67
guard total > 0 && step <= total else {
72
68
return
73
69
}
74
- await self . writeProgress (
70
+ try await self . writeProgress (
75
71
ProgressInfo . step (
76
72
timestamp: Date ( ) ,
77
73
percent: Int ( Double ( step) / Double( total) * 100 ) ,
@@ -80,8 +76,8 @@ struct JsonFileProgressReporter: ProgressReporterProtocol {
80
76
)
81
77
}
82
78
83
- func complete( success: Bool ) async {
84
- await self . writeProgress ( ProgressInfo . complete ( success: success) )
79
+ func complete( success: Bool ) async throws {
80
+ try await self . writeProgress ( ProgressInfo . complete ( success: success) )
85
81
}
86
82
87
83
func close( ) throws {
0 commit comments