Skip to content

Commit

Permalink
Document nil handling in Wrap, WithStack and WithCause
Browse files Browse the repository at this point in the history
  • Loading branch information
e-sumin committed Mar 20, 2024
1 parent 5ea0bbc commit e8dc80e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func Foo() error {

### Adding stack trace
If you are interested in adding information about the line and filename where the sentinel error happened, you can do the following:

**NOTE**: While the `WithStack` will return `nil` if passed `err` equals `nil`, we do not consider this good practice and recommend checking the `err` value before invocation.
```go
func Foo() error {
...
Expand All @@ -47,6 +49,8 @@ func Bar() error {

### Adding error cause information
Sometimes you might be interested in returning a sentinel error, but also add some cause error to it, in such cases you can do the following:

**NOTE**: While the `WithCause` will return `nil` if passed `err` equals `nil`, we do not consider this good practice and recommend checking the `err` value before invocation.
```go
func FetchSomething(ID string) error {
err := doSomething() // Here we have an error
Expand Down Expand Up @@ -74,6 +78,8 @@ func FooBar() error {

### Wrapping an error with a high-level message
Sometimes you might want to add some high-level information to an error before passing it up to the invoker.

**NOTE**: While the `Wrap` will return `nil` if passed `err` equals `nil`, we do not consider this good practice and recommend checking the `err` value before invocation.
```go
func LoadProfile() error {
err := makeAnApiCall()
Expand Down

0 comments on commit e8dc80e

Please sign in to comment.