@@ -6,10 +6,10 @@ import TSCUtility
66
77public protocol ProgressReporterProtocol {
88 /// 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
1010
1111 /// Completes the progress animation, indicating success or failure.
12- func complete( success: Bool ) async
12+ func complete( success: Bool ) async throws
1313
1414 /// Closes any resources used by the reporter, if applicable.
1515 func close( ) throws
@@ -23,15 +23,15 @@ struct ConsoleProgressReporter: ProgressReporterProtocol {
2323 self . reporter = PercentProgressAnimation ( stream: stream, header: header)
2424 }
2525
26- func update( step: Int , total: Int , text: String ) async {
26+ func update( step: Int , total: Int , text: String ) async throws {
2727 self . reporter. update ( step: step, total: total, text: text)
2828 }
2929
30- func complete( success: Bool ) async {
30+ func complete( success: Bool ) async throws {
3131 self . reporter. complete ( success: success)
3232 }
3333
34- func close( ) {
34+ func close( ) throws {
3535 // No resources to close for console reporter
3636 }
3737}
@@ -55,23 +55,19 @@ struct JsonFileProgressReporter: ProgressReporterProtocol {
5555 self . fileHandle = try FileHandle ( forWritingTo: URL ( fileURLWithPath: filePath. string) )
5656 }
5757
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)
6460
6561 self . fileHandle. write ( jsonData)
6662 self . fileHandle. write ( " \n " . data ( using: . utf8) ?? Data ( ) )
67- try ? self . fileHandle. synchronize ( )
63+ try self . fileHandle. synchronize ( )
6864 }
6965
70- func update( step: Int , total: Int , text: String ) async {
66+ func update( step: Int , total: Int , text: String ) async throws {
7167 guard total > 0 && step <= total else {
7268 return
7369 }
74- await self . writeProgress (
70+ try await self . writeProgress (
7571 ProgressInfo . step (
7672 timestamp: Date ( ) ,
7773 percent: Int ( Double ( step) / Double( total) * 100 ) ,
@@ -80,8 +76,8 @@ struct JsonFileProgressReporter: ProgressReporterProtocol {
8076 )
8177 }
8278
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) )
8581 }
8682
8783 func close( ) throws {
0 commit comments