Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Cleanup error usage #3386

Merged
merged 2 commits into from
Jul 3, 2018
Merged

Cleanup error usage #3386

merged 2 commits into from
Jul 3, 2018

Conversation

cpuguy83
Copy link
Member

What this PR does / why we need it:

Use github.com/pkg/errors for defining errors.
Instead of masking errors with fmt.Errorf(), uses errors.Wrap where appropriate.
Incidentally this also fixes some formatting issues in certain error messages.

@jackfrancis
Copy link
Member

@cpuguy83 thanks for this! In general we like to pave vendor/ changes discretely, and in advance to avoid merge conflicts. But because you authored the PR that induced these conflicts we're probably 👍 here :)

cpuguy83 added 2 commits July 2, 2018 13:51
Instead of masking errors with `fmt.Errorf()`, uses `errors.Wrap` where
appropriate.

Incidentally this also fixes some formatting issues in certain error
messages.
@codecov
Copy link

codecov bot commented Jul 2, 2018

Codecov Report

Merging #3386 into master will not change coverage.
The diff coverage is 19.88%.

@@           Coverage Diff           @@
##           master    #3386   +/-   ##
=======================================
  Coverage   54.51%   54.51%           
=======================================
  Files         104      104           
  Lines       15787    15787           
=======================================
  Hits         8606     8606           
  Misses       6429     6429           
  Partials      752      752

@cpuguy83
Copy link
Member Author

cpuguy83 commented Jul 2, 2018

Thanks! I did at least put the vendor change in a separate commit here (though I guess I did not on the last change).

This is rebased.

}

if len(uc.resourceGroupName) == 0 {
cmd.Usage()
return fmt.Errorf("--resource-group must be specified")
return errors.New("--resource-group must be specified")
Copy link
Member

Choose a reason for hiding this comment

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

Just curious: for error messages that aren't synthesizing downstream err objects with add'l string message context, what is the value of using github.com/pkg/errors? I.e., what the benefit of errors.New() over fmt.Errorf()?

Copy link
Member Author

Choose a reason for hiding this comment

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

errors.New() stores the stack information which can aid in debugging... e.g. you can fmt.Printf("+v") and see the full stack trace of this error.

@jackfrancis
Copy link
Member

/lgtm

@acs-bot
Copy link

acs-bot commented Jul 3, 2018

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cpuguy83, jackfrancis

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jackfrancis jackfrancis merged commit 9993e58 into Azure:master Jul 3, 2018
@cpuguy83 cpuguy83 deleted the cleanup branch July 3, 2018 00:50
@tariq1890 tariq1890 mentioned this pull request Jul 15, 2018
3 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants