Skip to content

Comments

Add wrap verb to formatted error outputs#817

Merged
autrilla merged 1 commit intogetsops:developfrom
mkatychev:develop
Feb 17, 2021
Merged

Add wrap verb to formatted error outputs#817
autrilla merged 1 commit intogetsops:developfrom
mkatychev:develop

Conversation

@mkatychev
Copy link
Contributor

@mkatychev mkatychev commented Feb 17, 2021

  • Replaces %v formatting of errors using fmt.Errorf with %w.
  • In cases where an Unwrap method is not used, %w behaves in the exact same way as %v.

Reference:

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.

This would allow returned errors such as this one to check and handle cases when the underlying error is os.ErrNotExist using os.IsNotExist(err):
https://github.com/mozilla/sops/blob/8e21de8dbc750f050a54d63209f2f1f93477168c/decrypt/decrypt.go#L21-L24

@autrilla autrilla self-requested a review February 17, 2021 21:21
Copy link
Contributor

@autrilla autrilla left a comment

Choose a reason for hiding this comment

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

Thanks!

@autrilla autrilla merged commit 0f2ebcf into getsops:develop Feb 17, 2021
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.

2 participants