Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FuncCallerInfo ¶
type FuncCallerInfo struct {
Name string `json:"name,omitempty"`
File string `json:"file,omitempty"`
Line int `json:"line,omitempty"`
Time time.Time `json:"time,omitempty"`
}
func GetFuncCallerInfo ¶
func GetFuncCallerInfo(skips ...int) FuncCallerInfo
func (FuncCallerInfo) String ¶
func (fci FuncCallerInfo) String() string
type StackError ¶
type StackError struct {
St FuncCallerInfo `json:"caller"`
// contains filtered or unexported fields
}
StackError wraps an error and holds the stack trace St (FuncCallerInfo)
Create with Errorf or Wrap (`stackerr.Errorf("%w", err)`) Print with `%+v` verb (or call err.Stack()) Use err.Unwrap() (or errors.Unwrap(err)) to retrieve underlying error
Example:
err := foo()
if err != nil {
return fmt.Errorf("%w", err)
}
in main, `log.Fatalf("%+v", err)`
func WrapN ¶ added in v0.1.2
func WrapN(err error, skip int) *StackError
WrapN with stack trace from caller's caller (nil error returns nil)
func (*StackError) Format ¶
func (s *StackError) Format(f fmt.State, c rune)
Format implements fmt.Formatter
%+v for nice stack trace, %+z for single-line version suitable for slog package
func (*StackError) MarshalText ¶ added in v0.1.2
func (s *StackError) MarshalText() ([]byte, error)
MarshalText for getting slog package to print %+z mode (no newlines)
func (*StackError) Stack ¶
func (s *StackError) Stack() FuncCallerInfo
func (*StackError) Underlying ¶
func (s *StackError) Underlying() error
func (*StackError) Unwrap ¶
func (s *StackError) Unwrap() error
Click to show internal directories.
Click to hide internal directories.