-
Notifications
You must be signed in to change notification settings - Fork 1k
ensure: tweaks to align no-vendor behavior and verbose/dry-run logging #1039
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -418,24 +418,30 @@ fail: | |
| } | ||
|
|
||
| // PrintPreparedActions logs the actions a call to Write would perform. | ||
| func (sw *SafeWriter) PrintPreparedActions(output *log.Logger) error { | ||
| func (sw *SafeWriter) PrintPreparedActions(output *log.Logger, verbose bool) error { | ||
| if sw.HasManifest() { | ||
| output.Printf("Would have written the following %s:\n", ManifestName) | ||
| m, err := sw.Manifest.MarshalTOML() | ||
| if err != nil { | ||
| return errors.Wrap(err, "ensure DryRun cannot serialize manifest") | ||
| if verbose { | ||
| m, err := sw.Manifest.MarshalTOML() | ||
| if err != nil { | ||
| return errors.Wrap(err, "ensure DryRun cannot serialize manifest") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that's an appropriate error message. Could we extract the "ensure DryRun " part to the caller? (same comment of the errors below) return errors.Wrap(err, "cannot serialize manifest")and errors.Wrap(sw.PrintPreparedActions(ctx.Out, ctx.Verbose), "ensure dry run failed")?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm inclined to agree, but I didn't want too much to creep into this PR. I like striping out "ensure dry run". Does it even need to be said at all, or could it be left out of both levels?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have stuff like that in our messages in places where we weren't consistently using the errors package and it helped narrow down where the messages were coming from. I've been removing these "it broke here" type messages, and either making sure that the original error had a good message and stack trace (i.e. it uses the errors package), or calling wrap and writing a message that uses full sentences that could be printed to the console and still make sense. 😁
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's do this in another PR. |
||
| } | ||
| output.Printf("Would have written the following %s:\n%s\n", ManifestName, string(m)) | ||
| } else { | ||
| output.Printf("Would have written %s.\n", ManifestName) | ||
| } | ||
| output.Println(string(m)) | ||
| } | ||
|
|
||
| if sw.writeLock { | ||
| if sw.lockDiff == nil { | ||
| output.Printf("Would have written the following %s:\n", LockName) | ||
| l, err := sw.lock.MarshalTOML() | ||
| if err != nil { | ||
| return errors.Wrap(err, "ensure DryRun cannot serialize lock") | ||
| if verbose { | ||
| l, err := sw.lock.MarshalTOML() | ||
| if err != nil { | ||
| return errors.Wrap(err, "ensure DryRun cannot serialize lock") | ||
| } | ||
| output.Printf("Would have written the following %s:\n%s\n", LockName, string(l)) | ||
| } else { | ||
| output.Printf("Would have written %s.\n", LockName) | ||
| } | ||
| output.Println(string(l)) | ||
| } else { | ||
| output.Printf("Would have written the following changes to %s:\n", LockName) | ||
| diff, err := formatLockDiff(*sw.lockDiff) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code is no longer printing the lock diff when Otherwise I either have to settle for no useful output (other than knowing that dep found changes), or I have to wade through dozens of lines of solve output just to see what new package would be written to my lock. 😀 e.g. Terse Verbose
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine with me. Should this apply to
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about reverting the whole method, so manifest and vendor in addition to the lock.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I definitely think that the vendor info e.g. Not so sure about the manifest though. I think it will print the entire manifest contents, even when only 1 thing has changed, right? Basically we don't have manifest diffing? If we don't have manifest diffing, and there's no issue for that, it would be great to make a new issue for that! 😁 From a user perspective, I'd prefer to only see changes when I ask for a dry-run, and put anything that is a "mega dump" under the verbose flag.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
|
|
@@ -447,9 +453,13 @@ func (sw *SafeWriter) PrintPreparedActions(output *log.Logger) error { | |
| } | ||
|
|
||
| if sw.writeVendor { | ||
| output.Println("Would have written the following projects to the vendor directory:") | ||
| for _, project := range sw.lock.Projects() { | ||
| output.Println(project) | ||
| if verbose { | ||
| output.Printf("Would have written the following %d projects to the vendor directory:\n", len(sw.lock.Projects())) | ||
| for _, project := range sw.lock.Projects() { | ||
| output.Println(project) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we prepend anything here like
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps another candidate for counts, like in #1037. I can include this one in a future PR. |
||
| } | ||
| } else { | ||
| output.Printf("Would have written %d projects to the vendor directory.\n", len(sw.lock.Projects())) | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
This is the only one to pass
ctx.Err, but I don't see a reason to.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.
Changed to
ctx.Outto align with others.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 think that we've been logging info to stdout and verbose to stderr?
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 see that now in some other places, but maybe we need an issue to document the policy and audit/align the existing usages.