-
Notifications
You must be signed in to change notification settings - Fork 55
Add progress reporter protocol #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add progress reporter protocol #394
Conversation
|
||
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, got it.
Sources/Swiftly/Install.swift
Outdated
"Downloaded \(String(format: "%.1f", downloadedMiB)) MiB of \(String(format: "%.1f", totalMiB)) MiB" | ||
) | ||
} catch { | ||
// Silently ignore progress update errors to avoid interrupting download |
There was a problem hiding this comment.
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.
d4ea316
to
db55485
Compare
db55485
to
af7b2d9
Compare
This PR contains