errors

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2021 License: MIT Imports: 5 Imported by: 11

README

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:

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:

func E(args ...interface{}) *Error

E.g.:

  • just error:
errors.E(err)
  • error with message:
errors.E(err, "new message to append")
  • error with type:
errors.E(err, errors.TypePlatformReques)
  • error with type and message:
errors.E(err, errors.TypePlatformReques, "new message to append")
  • error with type and meta:
errors.E(err, errors.TypePlatformRequest, errors.Params{
			"coin":   "Ethereum",
			"method": "CurrentBlockNumber",
		})
  • error with meta:
errors.E(err, errors.Params{
			"coin":   "Ethereum",
			"method": "CurrentBlockNumber",
		})
  • error with type and meta:
errors.E(err, errors.TypePlatformRequest, errors.Params{
			"coin":   "Ethereum",
			"method": "CurrentBlockNumber",
		})
  • error with type, message and meta:
errors.E(err, errors.TypePlatformRequest, "new message to append", errors.Params{
			"coin":   "Ethereum",
			"method": "CurrentBlockNumber",
		})
  • You can send the errors to sentry using .PushToSentry()
errors.E(err, errors.TypePlatformReques).PushToSentry()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Err error
	// contains filtered or unexported fields
}

Error represents a error's specification.

func E

func E(args ...interface{}) *Error

E create a new error. It returns the new error object

func T

func T(args ...interface{}) *Error

T create a new error with runtime stack trace.

func (*Error) Error

func (e *Error) Error() string

Error satisfy the built-in interface type is the conventional error interface. It returns a JSON object from an error object.

func (*Error) IsEmpty

func (e *Error) IsEmpty() bool

IsEmpty verify if the error object is empty, without meta and the original error. It returns true if is empty.

func (*Error) JSON

func (e *Error) JSON() interface{}

JSON creates a properly formatted JSON It return a JSON interface representation of error.

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaller interface.

func (*Error) Meta

func (e *Error) Meta() string

Meta gets the error's meta data into a string. It return the string representation of error.

func (*Error) SetMeta

func (e *Error) SetMeta(data Params) *Error

SetMeta sets the error's meta data. It return the error itself

func (*Error) String

func (e *Error) String() string

String returns a string from an error object.

type Params

type Params map[string]interface{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL