Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pantani/errors
Simple abstraction for errors.
https://github.com/pantani/errors
error error-handler error-handling error-log error-messages error-reporting errors go golang
Last synced: about 7 hours ago
JSON representation
Simple abstraction for errors.
- Host: GitHub
- URL: https://github.com/pantani/errors
- Owner: Pantani
- License: mit
- Created: 2020-03-28T15:47:43.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-26T01:33:11.000Z (over 3 years ago)
- Last Synced: 2024-06-21T08:26:53.633Z (5 months ago)
- Topics: error, error-handler, error-handling, error-log, error-messages, error-reporting, errors, go, golang
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Go Reference](https://pkg.go.dev/badge/github.com/Pantani/errors.svg)](https://pkg.go.dev/github.com/Pantani/errors)
[![codecov](https://codecov.io/gh/Pantani/errors/branch/master/graph/badge.svg?token=F6HFPDPW9J)](https://codecov.io/gh/Pantani/errors)# Simple error package
Simple abstraction for errors.
Use this package for create a new error.
An error in Go is any implementing interface with an Error() string method. We overwrite the error object by our error struct:```go
type Error struct {
Err error
Type Type
meta map[string]interface{}
stack []string
}
```To be easier the error construction, the package provides a function named E, which is short and easy to type:
```go
func E(args ...interface{}) *Error
```E.g.:
- just error:
```go
errors.E(err)
```- error with message:
```go
errors.E(err, "new message to append")
```- error with type:
```go
errors.E(err, errors.TypePlatformReques)
```- error with type and message:
```go
errors.E(err, errors.TypePlatformReques, "new message to append")
```- error with type and meta:
```go
errors.E(err, errors.TypePlatformRequest, errors.Params{
"coin": "Ethereum",
"method": "CurrentBlockNumber",
})
```- error with meta:
```go
errors.E(err, errors.Params{
"coin": "Ethereum",
"method": "CurrentBlockNumber",
})
```- error with type and meta:
```go
errors.E(err, errors.TypePlatformRequest, errors.Params{
"coin": "Ethereum",
"method": "CurrentBlockNumber",
})
```- error with type, message and meta:
```go
errors.E(err, errors.TypePlatformRequest, "new message to append", errors.Params{
"coin": "Ethereum",
"method": "CurrentBlockNumber",
})
```- You can send the errors to sentry using `.PushToSentry()`
```go
errors.E(err, errors.TypePlatformReques).PushToSentry()
```