Skip to content

Better errors replaces the standard error message with a more detailed one.

Notifications You must be signed in to change notification settings

sebastianwebber/berr

Repository files navigation

berr: Better Errors

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

Installation

go get github.com/sebastianwebber/berr@latest

Example

example

check ./examples/main.go for details.

berr

import "github.com/sebastianwebber/berr"

Index

Constants

const (
    // MaxStackDepth is the maximum number of stack frames to retrieve
    // when collecting a stack trace.
    MaxStackDepth = 100
)

Variables

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

About

Better errors replaces the standard error message with a more detailed one.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages