Better errors replaces the standard error message with a more detailed one. This makes it easier to debug your code and understand what is going on.
Yes, message output is inspired by the rust's anyhow
crate. :D
go get github.com/sebastianwebber/berr@latest
check
./examples/main.go
for details.
import "github.com/sebastianwebber/berr"
- Constants
- Variables
- func Errorf(format string, a ...any) error
- func Format(err error) string
- func Logger(err error, args ...any) *log.Logger
- func New(text string) error
- func Reset()
- type Config
const (
// MaxStackDepth is the maximum number of stack frames to retrieve
// when collecting a stack trace.
MaxStackDepth = 100
)
var (
// Options var is the default configuration used by this package
Options = Config{
PrintStack: false,
ShowCompleteStack: false,
}
)
func Errorf
func Errorf(format string, a ...any) error
Errorf returns a Better Error with a formatted string
func Format
func Format(err error) string
Format returns a pretty formatted error message. Heavily inspired by anyhow output: https://docs.rs/anyhow/latest/anyhow/
func Logger
func Logger(err error, args ...any) *log.Logger
Logger returns a *log.Logger with the error field set to the pretty error message
func New
func New(text string) error
New returns a Better Error with a interface compatible with the errors.New()
func Reset
func Reset()
Reset sets the default options for the package
type Config
type Config struct {
// PrintStack will print the stack trace of the error
// but ignores the functions related to the berr package
PrintStack bool
// ShowCompleteStack will print the complete stack trace
// including the functions related to the berr package
ShowCompleteStack bool
}
Generated by gomarkdoc