Skip to content

Conversation

roulpriya
Copy link
Contributor

This PR contains

  • Create a ProgressReporterProtocol to support an async function.


public protocol ProgressReporterProtocol {
/// Updates the progress animation with the current step, total steps, and an optional text message.
func update(step: Int, total: Int, text: String) async
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Since update can be fallible due to one of the implementations doing I/O operations, this can be declared as throws and then the try? become plain try and the original I/O error can flow all of the way to the top-level error reporting.

func update(step: Int, total: Int, text: String) async

/// Completes the progress animation, indicating success or failure.
func complete(success: Bool) async
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Same as above, this can be declared throws so that I/O errors reported on the complete can be thrown to an error reported with the original I/O error details.

}

private func writeProgress(_ progress: ProgressInfo) async {
let jsonData = try? self.encoder.encode(progress)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: From above, if this method is declared throws then the errors can be thrown directly to the caller with the particular details of the failed I/O operation.

private func writeProgress(_ progress: ProgressInfo) async {
let jsonData = try? self.encoder.encode(progress)
guard let jsonData = jsonData else {
await self.ctx.message("Failed to encode progress entry to JSON")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: It's great to see this message being reliably reported now that the method is async.

import SwiftlyCore
import SystemPackage
@preconcurrency import TSCBasic
import TSCUtility
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: It's great to see this TSC dependency being further isolated. The hope is to remove the dependency entirely someday, and use something that isn't deprecated, and adds to the size of the swiftly binary.

message: "\(version) does not exist at URL \(notFound.url), exiting")
} catch {
animation.complete(success: false)
try? await animation.complete(success: false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: It's good to do a best effort complete here so that the original error gets reported since that's probably the more relevant one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: It's good to do a best effort complete here so that the original error gets reported, since that's probably the more relevant one.

I didn't get this @cmcgee1024.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roulpriya in this catch block, there's an error that was thrown. The animation.complete() can also throw an error. I think that the first error is probably more important and should be the one that is thrown. This code is doing the right thing in my opinion. :+1

Copy link
Member

@cmcgee1024 cmcgee1024 Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roulpriya in this catch block, there's an error that was thrown. The animation.complete() can also throw an error. I think that the first error is probably more important and should be the one that is thrown. This code is doing the right thing in my opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, got it.

"Downloaded \(String(format: "%.1f", downloadedMiB)) MiB of \(String(format: "%.1f", totalMiB)) MiB"
)
} catch {
// Silently ignore progress update errors to avoid interrupting download
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (blocking): Let's at least report a message about this error so that it can be seen by someone or captured as part of stderr with a ctx.message(). It could have important details in VSCode integration someday.

@roulpriya roulpriya force-pushed the add-progress-reporter-protocol branch from d4ea316 to db55485 Compare June 27, 2025 16:00
@roulpriya roulpriya force-pushed the add-progress-reporter-protocol branch from db55485 to af7b2d9 Compare June 27, 2025 16:02
@cmcgee1024 cmcgee1024 merged commit 06bc674 into swiftlang:main Jun 27, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants