til/Development/Go/errors.md

24 lines
265 B
Markdown
Raw Normal View History

2020-07-13 09:40:47 +00:00
# [errors](https://golang.org/pkg/errors/)
Wrap error:
```go
err := fmt.Errorf("Something wrong: %w", rootErr)
```
Unwrap error:
```go
rootErr := errors.Unwrap(err)
```
2022-06-28 09:59:29 +00:00
Compare error:
```go
// Don't
if err == CustomErr
// Do
if errors.Is(err, CustomErr)
```