Skip to content

Add FlagErrorf; encapsulate FlagError.error#4584

Merged
adonovan merged 1 commit intotrunkfrom
FlagErrorf
Oct 21, 2021
Merged

Add FlagErrorf; encapsulate FlagError.error#4584
adonovan merged 1 commit intotrunkfrom
FlagErrorf

Conversation

@adonovan
Copy link
Copy Markdown
Contributor

This change hides the representation of FlagError, exposing two constructors:

  • FlagErrorf, which uses fmt.Errorf (and supports %w)
  • FlagErrorWrap(error), which is used in exactly one place.

Do we need the second one? Note that calling it instead of FlagErrorf("%s", err) is a behavior change.

@adonovan adonovan requested review from a team as code owners October 21, 2021 15:21
@adonovan adonovan requested review from mislav and samcoe and removed request for a team October 21, 2021 15:21
@cliAutomation
Copy link
Copy Markdown
Collaborator

Hi! Thanks for the pull request. Please ensure that this change is linked to an issue by mentioning an issue number in the description of the pull request. If this pull request would close the issue, please put the word 'Fixes' before the issue number somewhere in the pull request body. If this is a tiny change like fixing a typo, feel free to ignore this message.

Copy link
Copy Markdown
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Looks great!

I don't have strong opinions about FlagErrorWrap also being available. Would FlagErrorf("%w", err) be a functional equivalent to the wrap function?

@adonovan
Copy link
Copy Markdown
Contributor Author

I don't have strong opinions about FlagErrorWrap also being available. Would FlagErrorf("%w", err) be a functional equivalent to the wrap function?

No, because fmt.Errorf("%w", err) is not the identity function. (I had had the same question.)

I was initially inclined not to add the wrap function, but concluded that it is consistent with the abstraction. We already expose the concept of "the underlying error" through Unwrap; FlagErrorf("%w", err) doesn't let you control it.

@adonovan adonovan merged commit 2f7f224 into trunk Oct 21, 2021
@adonovan adonovan deleted the FlagErrorf branch October 21, 2021 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants