Skip to content
/ btw Public

BTW is an error library in Go. It can carry backtrace of the stack and customized context in errors.

License

Notifications You must be signed in to change notification settings

rumtid/btw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

BTW

BTW is an error library in Go. It can carry backtrace of the stack and customized context in errors.

Features

  • Wrap a backtrace of the stack, fold recursive functions
  • Attach customized context, shadow outers' duplicated keys
  • Format human friendly error information with stack and context
  • Make life easier :)

Install

Run following command:

go get github.com/rumtid/btw

Usage

import "github.com/rumtid/btw"

// btw.Trace() wraps the stack trace information.
// It is common to trace errors from other modules.
err := otherMod.Func()
if err != nil {
    return btw.Trace(err)
}

// btw.Attach() records additional details.
// For example, the i variable is attached, and labelled as "retries".
if err != nil {
    err = btw.Attach(err,
        "retries", i,
    )
    return err
}

// btw.Format() outputs the error in a human-readable fashion.
if err != nil {
    fmt.Println(btw.Format(err))
}
// Output:
// error: something wrong
//         from main.Dial() at github.com/rumtid/example.go:10
//         [ retries ]    2    by main.Dial()

About

BTW is an error library in Go. It can carry backtrace of the stack and customized context in errors.

Resources

License

Stars

Watchers

Forks

Languages