erero is a simple error-handling package designed to log errors along with their context and location.
package name erero doesn't conflict with Go's standard errors
package or other popular libraries like github.com/pkg/errors
or github.com/go-kratos/kratos/v2/errors
.
go get github.com/yyle88/erero
package main
import (
"fmt"
"math/rand/v2"
"github.com/yyle88/erero"
)
func sub1() error {
if rand.IntN(100) < 30 {
return erero.New("wrong")
}
return nil
}
func sub2() error {
if num := rand.IntN(100); num < 20 {
return erero.Errorf("wrong num=%d", num)
}
return nil
}
func run() error {
if err := sub1(); err != nil {
return erero.WithMessage(err, "sub1 is wrong")
}
if err := sub2(); err != nil {
return erero.WithMessagef(err, "sub2 is wrong")
}
return nil
}
func main() {
if err := run(); err != nil {
panic(erero.Wro(err))
}
fmt.Println("success")
}
erero
is open-source and released under the MIT License. See the LICENSE file for more information.
Welcome to contribute to this project by submitting pull requests or reporting issues.
If you find this package helpful, give it a star on GitHub!
Thank you for your support!
Happy Coding with erero
! 🎉
Give me stars. Thank you!!!