Skip to content

Commit

Permalink
Readme and docs (#53)
Browse files Browse the repository at this point in the history
* demonstrate typed slog

* remove references to ErrorGroup

---------

Co-authored-by: Greg Weber <[email protected]>
  • Loading branch information
gregwebs and Greg Weber authored Jan 21, 2025
1 parent c473b9c commit afae662
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ If you don't want to bother with adding any additional metadata, you can just us
You can also add context with slog attributes with `Wraps`

```go
return errors.Wraps(err, "failure", "id", 5, "key", "value)
return errors.Wraps(err, "failure message", slog.Int("id", 5), slog.String("key", "value))
// or untyped just as in slog
return errors.Wraps(err, "failure message", "id", 5, "key", "value)
```

## Using with standard library errors
Expand Down
2 changes: 1 addition & 1 deletion errwrap/go_123.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// UnwrapGroups will unwrap errors visiting each one.
// Any ErrorGroup is expanded and traversed
// An error that defines Unwrap() []error is expanded and traversed
// This is a depth-first traversal, doing the unwrap first and the expansion second.
// This can be used for functionality similar to errors.As but it also expands error groups.
func UnwrapGroups(err error) iter.Seq[error] {
Expand Down
2 changes: 1 addition & 1 deletion errwrap/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func writeString(w io.Writer, s string) {
// UnwrapGroups is now preferred for those using Go version >= 1.23.
// Note that WalkDeep uses the opposite convention for boolean return values compared to golang iterators.
// WalkDeep does a depth-first traversal of all errors.
// Any ErrorGroup is traversed (after first unwrapping deeply).
// An error that defines Unwrap() []error is expanded and traversed
// The visitor function can return true to end the traversal early
// If iteration is ended early, WalkDeep will return true, otherwise false.
func WalkDeep(err error, visitor func(err error) bool) bool {
Expand Down

0 comments on commit afae662

Please sign in to comment.