-
Notifications
You must be signed in to change notification settings - Fork 589
[image-inspect]: stdout/stderr and logging refactor #1044
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
base: main
Are you sure you want to change the base?
[image-inspect]: stdout/stderr and logging refactor #1044
Conversation
|
@saehejkang Throwing InspectError at the end causes swift-argument-parser to print the raw struct details (e.g. Error: InspectError(...)) to stderr. Since you are already logging specific errors via Logger, this final error print is redundant and noisy. My Suggestion: Throw ExitCode.failure instead of InspectError to exit non-zero without extra noise, OR make InspectError conform to LocalizedError with a clean errorDescription. |
|
@Ronitsabhaya75 My initial thought process was to make |
|
@saehejkang I see your point about keeping the implementation simple! However, we can actually eliminate the noisy raw struct print without adding complex error types. If InspectError conforms to LocalizedError and returns a generic summary, swift-argument-parser will print that instead of the raw struct dump. extension ImageInspect.InspectError: LocalizedError {
var errorDescription: String? {
// We already logged specific errors above, so a simple summary suffices here.
return "Failed to inspect \(failed.count) image(s)."
}
}This keeps the error handling logic exactly as you have it but makes the CLI output much cleaner for the end user. |
|
@saehejkang Did |
|
@saehejkang @Ronitsabhaya75 also see the PR I pushed for creating a ManagedResource protocol. What do you think about having ContainerResource or ContainerAPIClient define an error type for ManagedResource that can wrap I won't do any error-related work in that PR (I'm going to force push a rewrite of what I have, made a lot of changes), so feel free to play around in this one and we can work out something coordinated. |
I like the idea of having a single If we follow one simple pattern, that could alleviate issues I was running into. For example, in the ClientImage.get() here, updating the return to be However, there could be another discussion on even if commands should even be throwing ANY errors. Should they only be thrown in the client/server functions? |
Yeah, one model I'd had in my head was that the API service and client would throw errors that were principally data carriers with minimal message text, and any code that uses the API client is responsible for taking the data and presenting it as it saw fit. That's "informed" by my ignorance of how localization works for errors; that model assumes that the caller of the client is best equipped to localize errors. It does feel less fussy if the errors thrown by the API server and client are ready to present without any additional work on the caller's part. What do you think about a PartialError type that's a holder for a wrapped collection of errors from a compound operation? The PartialError meaning would be "it's up to you to determine whether this constitutes a proper error". |
|
@saehejkang Also make sure to rebase to pick up the test fix! |
|
I also just pushed #1066 that gives all the commands a logger that outputs the message and metadata only at levels other than debug and trace, and includes an ISO timestamp at those levels. What I'd like to do is use structured logging principles for all our CLI logging. I'd written up these guidelines elsewhere and think they're applicable here: Use the following guidelines when crafting log messages:
Conventional Structured Logging Fields
|
|
@jglogan i'll have look once I'm good after my interview next week |
Type of Change
Motivation and Context
Relates to #642.
StderrLogHandlerI found these updates make error propogation/handling a lot easier. If this is the correct direction we want to take, I will start by making updates to all the
imagecommands before continuing on #832.Testing