Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <git@zjvandeweg.nl>2020-12-04 11:31:37 +0300
committerZeger-Jan van de Weg <git@zjvandeweg.nl>2020-12-04 11:31:37 +0300
commitf5c6f6efe69a4c23fb1f10cebb66c47f90f1a70c (patch)
tree90bd2f8174944ce90c8de8b67b8373d64b5ae3ca /STYLE.md
parenta8830191463f17ea77648a3447f5602c7c8dfed5 (diff)
parent037a9ddab8a914583c12804ff5c855bef349472b (diff)
Merge branch 'ps-errors-wrapping' into 'master'
Use %w to wrap errors See merge request gitlab-org/gitaly!2877
Diffstat (limited to 'STYLE.md')
-rw-r--r--STYLE.md12
1 files changed, 7 insertions, 5 deletions
diff --git a/STYLE.md b/STYLE.md
index cfec09ccc..64319a6b7 100644
--- a/STYLE.md
+++ b/STYLE.md
@@ -10,11 +10,13 @@ code is accessible to different developers with varying setups.
## Errors
-### Use %v when wrapping errors
+### Use %w when wrapping errors
-Use `%v` when wrapping errors with context.
+Use `%w` when wrapping errors with context.
- fmt.Errorf("foo context: %v", err)
+ fmt.Errorf("foo context: %w", err)
+
+It allows to inspect the wrapped error by the caller with [`errors.As`](https://golang.org/pkg/errors/#As) and [`errors.Is`](https://golang.org/pkg/errors/#Is). More info about `errors` package capabilities could be found in the [blog post](https://blog.golang.org/go1.13-errors).
### Keep errors short
@@ -23,10 +25,10 @@ them. To be a good neighbor to the rest of the call stack we should keep
our errors short.
// Good
- fmt.Errorf("peek diff line: %v", err)
+ fmt.Errorf("peek diff line: %w", err)
// Too long
- fmt.Errorf("ParseDiffOutput: Unexpected error while peeking: %v", err)
+ fmt.Errorf("ParseDiffOutput: Unexpected error while peeking: %w", err)
### Use lower case in errors