-
Notifications
You must be signed in to change notification settings - Fork 101
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
Log package origins #1104
Log package origins #1104
Conversation
Log local paths with absolute path Improved error messages
Fixed integration test
@ANeumann82 reader_tar.go still has a few Wrapf usages in them. approving, but would you please fix those before you merge? :) Thanks! |
More cleanup of pck/errors
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.
Could you please provide an example outputs the CLI gives after this change to be able to review? Since this is changing the CLI output to the user that's the thing I am most interested about and I am kind of worried some of the %w will end up with weird output
see #1057 for inspiration :-)
@@ -26,13 +27,13 @@ func ReadDir(fs afero.Fs, path string) (*packages.Package, error) { | |||
// 1. get files | |||
files, err := FromDir(fs, path) | |||
if err != nil { | |||
return nil, errors.Wrap(err, "while parsing package files") | |||
return nil, fmt.Errorf("while parsing package files: %w", err) |
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.
I don't understand why are we wrapping the error here, do we need in the upper layers distinguish between some error type? Otherwise this would end up in a pretty weird error message printed out.
btw. I would say Wrapf is more %v than %w. I think %w has a bit of different use cases. Recommend reading https://blog.golang.org/go1.13-errors including when to wrap (in case you did not so far)
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.
Well, with regards to %v vs %w: From what I understand (and see from testing) %w just wraps the error, and allows it to be unwrappable - apart from that it behaves like %v. Which says to me, it's generally a good idea to use %w instead of %v.
In Go 1.13, the fmt.Errorf function supports a new %w verb. When this verb is present, the
error returned by fmt.Errorf will have an Unwrap method returning the argument of %w,
which must be an error. In all other ways, %w is identical to %v.
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.
I just have this question in another PR. To quote that same blog post:
In other words, wrapping an error makes that error part of your API. If you don't want to
commit to supporting that error as part of your API in the future, you shouldn't wrap the error.
It’s important to remember that whether you wrap or not, the error text will be the same. A
person trying to understand the error will have the same information either way; the choice to
wrap is about whether to give programs additional information so they can make more informed
decisions, or to withhold that information to preserve an abstraction layer.
We should get an agreement on this. Personally, I'm leaning towards:
- Using
%v
by default to preserve abstractions boundaries - Using
%w
intentionally when exposing the underlying error type is necessary
And since, for now, we're the only users of our internal API, whenever I see %w
in code, I expect somebody up in the calling chain to unwrap it. Thoughts?
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.
+1 to what @zen-dog wrote
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.
I do tend to lean towards: More information is better than less information, but I do get the abstraction boundaries. Coming from Java, I hate to not wrap exceptions, because of the enclosed stack traces, but as we don't have them here, I should probably adjust.
So, I can agree with @zen-dog proposal to use %v
per default any only using %w
when we expect to unwrap on the caller side. I don't think there needs to be an existing unwrap, but a high possibility and use case for an unwrap to happen though.
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.
I've changed the %w
s to %v
. I don't think in this area we don't need to wrap any errors
@alenkacz Could you re-review? |
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.
Let's get an agreement on the error wrapping topic. But I think we don't need to and should not wrap an errors that are implementation details and should not be exposed.
Also what do you think about a slightly different wording? Instead of kafka is a local file package
something like installing package 'kafka' from a local folder 'kafka'
or something along those lines and also change the others in similar manner. Just a suggestion, I find it a bit nicer :)
I kind of like the idea, but implementing that would be a tad difficult at the moment. The current logs are in the It would be possible to add the package type to the package.Package struct, or to extend the struct for the different package types, i'm not sure it's worth the effort right now though. |
# Conflicts: # pkg/kudoctl/packages/reader/read_dir.go # pkg/kudoctl/packages/reader/reader_tar.go
@ANeumann82 oh I see, makes sense, thanks for the explanation. Oh now I see I am still rejecting, I was hoping I already dismissed that, sorry! |
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.
👍
What this PR does / why we need it:
Log package origins when installing
Log local paths with absolute path
Improved error messages
Fixes #1101
The original error case: User has a directory "kafka" in the cwd:
New output without "kafka" directory in cwd:
New output with direct URL:
Output with an (invalid) relative local directory