Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetStackTraces ¶ added in v1.4.0
func GetStackTraces(err error) iter.Seq2[error, StackTrace]
GetStackTraces returns a sequence of errors and their associated StackTrace.
This function recursively returns errors and stack traces by repeating the following process:
1. If the given error has a StackTrace itself, this function returns the wrapped error and its StackTrace
- In this case, the iterator returns only one error.
2. If the given error has an Unwrap() error function, this function calls it and tries to process step 1 again 3. If the given error has an Unwrap() []error function, this function calls it and tries to process step 1 for each error in the returned slice
func WithStackTrace ¶
WithStackTrace creates an error with a StackTrace.
If err already has a StackTrace, this function returns err as-is.
Also, if err is nil, this function returns nil.
Types ¶
type FuncInfo ¶
type FuncInfo struct {
// Name is the name of the function.
Name string
// File is the source file where the function is defined.
File string
// Line is the line number in that file.
Line int
}
FuncInfo contains values obtained from runtime.Func.
type StackTrace ¶
type StackTrace []FuncInfo
StackTrace is an array of FuncInfo.
func GetAttachedStackTrace ¶ added in v1.1.0
func GetAttachedStackTrace(err error) (StackTrace, bool)
GetAttachedStackTrace returns the StackTrace if the given error has one.
The returned bool indicates whether the given error has a StackTrace.
func GetCurrentStackTrace ¶ added in v1.3.0
func GetCurrentStackTrace() StackTrace
GetCurrentStackTrace returns the current StackTrace.
func GetStackTrace ¶
func GetStackTrace(err error) StackTrace
GetStackTrace returns a StackTrace for err.
If err does not have a StackTrace, this function creates the current StackTrace.
Also, if err is nil, this function returns nil.
func (StackTrace) String ¶
func (s StackTrace) String() string
String formats StackTrace using FuncInfo.String.