-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwith_stack.go
More file actions
23 lines (20 loc) · 802 Bytes
/
with_stack.go
File metadata and controls
23 lines (20 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package errors
import "github.com/frederik-jatzkowski/errors/internal"
// WithStack annotates err with a stack trace at the point [WithStack] was called, even if one is already present.
// If err is nil, [WithStack] returns nil.
//
// This allows explicit recording of stack traces when needed.
// The most likely use case for this is wrapping errors that originated in other goroutines.
// Because each goroutine has its own stack, you might want to capture additionally stack traces when the error tree spans multiple goroutines.
//
// Do not use this under normal operations, use [Errorf] and [Join] for wrapping errors.
func WithStack(err error) error {
if err == nil {
return nil
}
return &internal.WithStack{
Explicit: true,
Inner: err,
St: internal.NewStackTrace(1),
}
}