A flaw is Golang is a replacement of errors package
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
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
We are open for any contributions. Just fork the project.