modulepackage
0.0.0-20230111045222-8efffb46800b
Repository: https://github.com/phogolabs/flaw.git
Documentation: pkg.go.dev
# README
flaw
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.
# Packages
No description provided by the author
# Functions
Cause returns the error's cause.
Code returns the code from an error.
Context returns the error's context.
Details returns the error's details.
Errorf creates a new error.
Message returns the error's message.
NewStackTrace creates a new StackTrace.
NewStackTraceAt creates a new stack trace at given position.
Status returns the status from an error.
Wrap wraps an error.
# Type aliases
ErrorCollector is a slice of errors.
ErrorConstant represents an error that can create a constant / sentinel error such as io.EOF.
Map is an alias to map[string]interface{}.
StackFrame represents a program counter inside a stack frame.
StackTrace is stack of StackFrames from innermost (newest) to outermost (oldest).