Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package tracerr

import (
"fmt"
"log/slog"
"runtime"
)

Expand All @@ -20,6 +21,7 @@ type Error interface {
Error() string
StackTrace() []Frame
Unwrap() error
LogValue() slog.Value
}

type errorData struct {
Expand Down Expand Up @@ -114,6 +116,13 @@ func (e *errorData) StackTrace() []Frame {
return e.frames
}

func (e *errorData) LogValue() slog.Value {
return slog.GroupValue(
slog.String("error", e.Error()),
slog.Any("stack_trace", Sprint(e.err)),
)
}

// Unwrap returns the original error.
func (e *errorData) Unwrap() error {
return e.err
Expand Down