errors

package module
v0.0.0-...-3c79b56 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 5 Imported by: 35

README

errors

Build Status | codecov | Go Report Card | GoDoc

Error handling with caused-by and stack.

If i miss something or you have something interesting, please be part of this project. Let me know! My contact is at the end.

Dependecy Management

Dependency

Project dependencies are managed using Dep. Read more about Dep.

  • Get dependency manager: go get github.com/joaosoft/dependency
  • Install dependencies: dependency get
Go
go get github.com/joaosoft/errors

Usage

This examples are available in the project at examples/main.go

var (
	ErrorOne = errors.New(errors.LevelError, 1, "Error one")
	ErrorTwo = errors.New(errors.LevelError, 2, "Error two")
)

func main() {
	fmt.Println("\nADDING ERRORS!\n")

	errs := errors.Add(ErrorOne).
		Add(ErrorTwo)

	fmt.Println(errs.Cause())

	fmt.Println(errs.Stack)
	fmt.Println(errs.Previous.Stack)

	fmt.Println("\nDONE!")
}

Known issues

Follow me at

Facebook: https://www.facebook.com/joaosoft

LinkedIn: https://www.linkedin.com/in/jo%C3%A3o-ribeiro-b2775438/

If you have something to add, please let me know joaosoft@gmail.com

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Throw

func Throw(up Exception)

Types

type Block

type Block struct {
	Try     func()
	Catch   func(Exception)
	Finally func()
}

func NewBlock

func NewBlock(try func(), catch func(Exception), finally func()) *Block

func (Block) Do

func (block Block) Do()

type Error

type Error struct {
	Previous *Error      `json:"previous,omitempty"`
	Level    Level       `json:"level"`
	Code     interface{} `json:"code"`
	Message  string      `json:"message"`
	Stack    string      `json:"stack"`
}

func Add

func Add(err *Error) *Error

func New

func New(level Level, code interface{}, err interface{}, params ...interface{}) *Error

func (*Error) Add

func (e *Error) Add(err *Error) *Error

func (*Error) Cause

func (e *Error) Cause() string

func (*Error) Error

func (e *Error) Error() string

func (*Error) Errors

func (e *Error) Errors() []*Error

func (*Error) Format

func (e *Error) Format(values ...interface{}) *Error

func (*Error) String

func (e *Error) String() string

type ErrorList

type ErrorList []*Error

func AddList

func AddList(errs ...*Error) *ErrorList

func (*ErrorList) Add

func (el *ErrorList) Add(err *Error) *ErrorList

func (*ErrorList) IsEmpty

func (el *ErrorList) IsEmpty() bool

func (*ErrorList) Len

func (el *ErrorList) Len() int

func (*ErrorList) String

func (el *ErrorList) String() string

type Exception

type Exception interface{}

type Level

type Level int
const (
	LevelPanic Level = iota // LevelPanic, when there is no recover
	LevelFatal              // LevelFatal, when the error is fatal to the application
	LevelError              // LevelError, when there is a controlled error
	LevelWarn               // LevelWarn, when there is a warning
	LevelInfo               // LevelInfo, when it is a informational message
	LevelDebug              // LevelDebug, when it is a debugging message
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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