https://github.com/sebastianwebber/berr
Better errors replaces the standard error message with a more detailed one.
https://github.com/sebastianwebber/berr
error-handling golang golang-error-handling golang-errors golang-library golang-package
Last synced: 9 days ago
JSON representation
Better errors replaces the standard error message with a more detailed one.
- Host: GitHub
- URL: https://github.com/sebastianwebber/berr
- Owner: sebastianwebber
- Created: 2024-03-20T15:34:21.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-14T23:45:22.000Z (2 months ago)
- Last Synced: 2025-04-15T00:27:24.683Z (2 months ago)
- Topics: error-handling, golang, golang-error-handling, golang-errors, golang-library, golang-package
- Language: Go
- Homepage:
- Size: 1.94 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
# `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](https://docs.rs/anyhow/latest/anyhow/). :D
## Installation
```shell
go get github.com/sebastianwebber/berr@latest
```## Example

> check [`./examples/main.go`](./examples/main.go) for details.# berr
```go
import "github.com/sebastianwebber/berr"
```## Index
- [Constants](<#constants>)
- [Variables](<#variables>)
- [func Errorf\(format string, a ...any\) error](<#Errorf>)
- [func Format\(err error\) string](<#Format>)
- [func Logger\(err error, args ...any\) \*log.Logger](<#Logger>)
- [func New\(text string\) error](<#New>)
- [func Reset\(\)](<#Reset>)
- [type Config](<#Config>)## Constants
```go
const (
// MaxStackDepth is the maximum number of stack frames to retrieve
// when collecting a stack trace.
MaxStackDepth = 100
)
```## Variables
```go
var (
// Options var is the default configuration used by this package
Options = Config{
PrintStack: false,
ShowCompleteStack: false,
}
)
``````go
func Errorf(format string, a ...any) error
```Errorf returns a Better Error with a formatted string
```go
func Format(err error) string
```Format returns a pretty formatted error message. Heavily inspired by anyhow output: https://docs.rs/anyhow/latest/anyhow/
```go
func Logger(err error, args ...any) *log.Logger
```Logger returns a \*log.Logger with the error field set to the pretty error message
```go
func New(text string) error
```New returns a Better Error with a interface compatible with the errors.New\(\)
```go
func Reset()
```Reset sets the default options for the package
```go
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]()