From afae6627ff7ccdc4b47f37db18b2d05fec1ab9b2 Mon Sep 17 00:00:00 2001 From: Greg Weber <1183+gregwebs@users.noreply.github.com> Date: Tue, 21 Jan 2025 06:43:02 -0600 Subject: [PATCH] Readme and docs (#53) * demonstrate typed slog * remove references to ErrorGroup --------- Co-authored-by: Greg Weber --- README.md | 4 +++- errwrap/go_123.go | 2 +- errwrap/wrap.go | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 66d16e1..73c285e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/errwrap/go_123.go b/errwrap/go_123.go index dbc595d..a1d8942 100644 --- a/errwrap/go_123.go +++ b/errwrap/go_123.go @@ -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] { diff --git a/errwrap/wrap.go b/errwrap/wrap.go index bbae33c..e3b2d8c 100644 --- a/errwrap/wrap.go +++ b/errwrap/wrap.go @@ -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 {