From afd8013bf616a5d46d422ad8cc0a793c4acdbacb Mon Sep 17 00:00:00 2001 From: Josue Giron Date: Sat, 21 Nov 2026 19:16:02 +0000 Subject: [PATCH] refactor: read the error detail through errors.Detail errors v0.7.0 deprecates the exported Wrapper field and adds Detail, which returns the same text. Reading it through the accessor lets errors v0.8.0 remove Wrapper and its go-errors dependency (ERR-07). The logged debug attribute is unchanged. Co-Authored-By: Claude Opus 5.5 --- error_test.go | 15 +++++++++++++++ go.mod | 2 +- go.sum | 4 ++-- internal/codederror/codederror.go | 6 +----- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/error_test.go b/error_test.go index f9075b6..86e2329 100644 --- a/error_test.go +++ b/error_test.go @@ -285,3 +285,18 @@ func TestNonCodedErrorAttributeStaysString(t *testing.T) { }) } } + +func TestCodedErrorAttributeOfStacklessSentinelHasEmptyDebug(t *testing.T) { + var buf bytes.Buffer + instance := New(WithJSONHandler(&buf)) + + instance.Error("failed", "error", errLogTitleRequired) + + group, ok := decodeRecord(t, &buf)["error"].(map[string]any) + if !ok { + t.Fatalf("expected an error group, got %q", buf.String()) + } + if debug, has := group["debug"]; !has || debug != "" { + t.Fatalf("expected an empty debug attribute, got %v", group) + } +} diff --git a/go.mod b/go.mod index d613c8b..b598028 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,6 @@ module github.com/jgolang/log go 1.26.2 -require github.com/jgolang/errors v0.6.2 +require github.com/jgolang/errors v0.7.0 require github.com/go-errors/errors v1.5.1 // indirect diff --git a/go.sum b/go.sum index 2426757..7285299 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8bk= github.com/go-errors/errors v1.5.1/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= -github.com/jgolang/errors v0.6.2 h1:862DCmlZowra5H198sQgqInMLBTsC5Ani51J37k4XMM= -github.com/jgolang/errors v0.6.2/go.mod h1:7jzxJ5Ox468U7Jk0R+JWI3sfPfLGSwPOie7ISDYlVhY= +github.com/jgolang/errors v0.7.0 h1:vOxGpGXUkevRLkGHRyJmPmlsWUN9GY5/kc9vw3krEzM= +github.com/jgolang/errors v0.7.0/go.mod h1:7jzxJ5Ox468U7Jk0R+JWI3sfPfLGSwPOie7ISDYlVhY= diff --git a/internal/codederror/codederror.go b/internal/codederror/codederror.go index 38ddedd..7f7ecb6 100644 --- a/internal/codederror/codederror.go +++ b/internal/codederror/codederror.go @@ -63,11 +63,7 @@ func GroupWithText(key string, err error, coded *errors.Error) slog.Attr { } func fields(coded *errors.Error) []slog.Attr { - debug := "" - if coded.Wrapper != nil { - debug = coded.Wrapper.Error() - } - + debug := coded.Detail() origin := slog.Attr{Key: "origin", Value: coded.StackTrace()} code := errors.CodeOf(coded) if code == nil {