golazy.dev
–
golazy.dev
/
lazyerrors
Index
|
Files
package lazyerrors
import "golazy.dev/lazyerrors"
Functions
func New
New formats an error like fmt.Errorf, prefixes it with the caller name, and records a backtrace beginning at the caller.
func New(format string, args ...any) error
Types
type Frame
Frame is one recorded application backtrace frame.
type Frame struct {
Function string
File string
Line int
}
func (f Frame) String
func (f Frame) String() string
Package lazyerrors records caller context and backtraces for application errors.
Use New where application code wants to return an error through the GoLazy controller or service stack with enough local context for debugging:
return lazyerrors.New("load post %q: %w", postID, err)The returned error message is prefixed with the caller, such as "posts.PostsController.Show: load post ...". Formatting follows fmt.Errorf, including support for %w wrapping. Errors with one wrapped cause implement Unwrap() error; errors with multiple wrapped causes implement Unwrap() []error. Code that needs the recorded trace can use errors.As with a local interface{ Backtrace() []lazyerrors.Frame }. Frame implements String for compact log output and also exposes Function, File, and Line fields.