https://github.com/PumpkinSeed/errors
Simple and efficient error package
https://github.com/PumpkinSeed/errors
Last synced: 9 months ago
JSON representation
Simple and efficient error package
- Host: GitHub
- URL: https://github.com/PumpkinSeed/errors
- Owner: PumpkinSeed
- License: apache-2.0
- Created: 2020-01-08T21:12:51.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-03-31T13:23:10.000Z (over 3 years ago)
- Last Synced: 2024-07-31T20:51:26.747Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - errors - The most simple error wrapper with awesome performance and minimal memory overhead. (Error Handling / Search and Analytic Databases)
- awesome-go-cn - errors
- awesome-go-plus - errors - The most simple error wrapper with awesome performance and minimal memory overhead.  (Error Handling / Search and Analytic Databases)
- awesome-go-cn - errors
- awesome-go - errors - The most simple error wrapper with awesome performance and minimal memory overhead. (Error Handling / Search and Analytic Databases)
- awesome-go - errors - The most simple error wrapper with awesome performance and minimal memory overhead. (Error Handling / Search and Analytic Databases)
- awesome-go-with-stars - errors - The most simple error wrapper with awesome performance and minimal memory overhead. (Error Handling / Search and Analytic Databases)
- awesome-go - errors - The most simple error wrapper with awesome performance and minimal memory overhead. (Error Handling / Search and Analytic Databases)
- fucking-awesome-go - errors - The most simple error wrapper with awesome performance and minimal memory overhead. (Error Handling / Search and Analytic Databases)
- awesome-Char - errors - The most simple error wrapper with awesome performance and minimal memory overhead. (Error Handling / Advanced Console UIs)
- awesome-go-cn - errors
- awesome-go - errors - The most simple error wrapper with awesome performance and minimal memory overhead. (Error Handling / Advanced Console UIs)
- awesome-go - errors - The most simple error wrapper with awesome performance and minimal memory overhead. (Error Handling / Search and Analytic Databases)
- awesome-go-extra - errors - 01-08T21:12:51Z|2022-03-31T13:23:10Z| (Error Handling / Advanced Console UIs)
README
[](https://travis-ci.com/PumpkinSeed/errors)
[](https://goreportcard.com/report/github.com/PumpkinSeed/errors)
[](http://godoc.org/github.com/PumpkinSeed/errors)
[](http://gocover.io/github.com/PumpkinSeed/errors)
# Errors
Simple error package for Go with minimal allocation and high performance. Optimized to keep error on function stack.
### Motivation
I found out that the available error packages too complex for the simple purpose or not achieve the simple goal.
### Purpose & Goal
Maintain an error chain (some kind of list of errors), and let the system to check whether the error's type caused the actual error or not.
### Usage
```go
package main
import (
stderrors "errors"
"github.com/PumpkinSeed/errors"
)
var ErrGlobal = errors.New("global err")
var ErrGlobal2 = errors.New("global err 2")
var ErrNotUsed = errors.New("not used err")
func main() {
err := f3()
stderrors.Is(err, ErrGlobal) // true
stderrors.Is(err, ErrGlobal2) // true
stderrors.Is(err, ErrNotUsed) // false
println(err.Error()) // "global err 2: global err: string1"
}
func f1() error {
return errors.New("string1")
}
func f2() error {
return errors.Wrap(f1(), ErrGlobal)
}
func f3() error {
return errors.Wrap(f2(), ErrGlobal2)
}
```