Skip to content

phogolabs/flaw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flaw

Documentation License Build Status Coverage Go Report Card

A flaw is Golang is a replacement of errors package

Installation

Make sure you have a working Go environment. Go version 1.13.x is supported.

See the install instructions for Go.

To install flaw, simply run:

$ go get github.com/phogolabs/flaw

Getting Started

Wrapping an error:

err := flaw.Wrap(sql.ErrNoRows).
	WithMessage("user does not exist").
	WithCode(404)

If you print the error with fmt.Println(err) you will receive the following output:

code: 404 message: user does not exist cause: sql: no rows in result set

If you want more detailed information, you can use fmt.Printf("%+v", err) formatting:

    code: 404
 message: user does not exist
   cause: sql: no rows in result set
   stack:
 --- /Users/ralch/go/src/github.com/phogolabs/flaw/cmd/main.go:19 (main)
 --- /usr/local/Cellar/go/1.13.1/libexec/src/runtime/proc.go:203 (main)
 --- /usr/local/Cellar/go/1.13.1/libexec/src/runtime/asm_amd64.s:1357 (goexit)

Collecting multiple errors:

errs := flaw.ErrorCollector{}
errs = append(errs, fmt.Errorf("insufficient funds"))
errs = append(errs, fmt.Errorf("maximum allowance reached"))

Then you can print the error fmt.Println(errs):

[insufficient funds, maximum allowance reached]

You can print the result with better formatting fmt.Printf("%+v", errs):

 --- insufficient funds
 --- maximum allowance reached

Contributing

We are open for any contributions. Just fork the project.

About

A Golang errors package on steroids

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages