grace

package module
v0.0.0-...-d1b62e9 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2018 License: GPL-3.0 Imports: 3 Imported by: 3

README

Build status GoReport GoDoc License Gitter


Handle recover, panic and errors in a graceful way


Quickstart

go get github.com/oxequa/grace

The following is a simple example that handles a panic and returns the error without the program crash.

package main

import (
  "fmt"
  "github.com/oxequa/grace"
)

func example() (e error){
  defer grace.Recover(&e) // save recover error and stack trace to e
  numbers := []int{1, 2}
  fmt.Println(numbers[3]) // panic out of index
  return
}

func main() {
  err := example() // no panic occur
  fmt.Println(err)
  fmt.Println("End")
}

Documentation

You can read the full documentation of Grace here.

Contributing

Please read our guideline here.

License

Grace is licensed under the GNU GENERAL PUBLIC LICENSE V3.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Def

func Def(e error, v ...interface{}) error

Def if error is nil return a new error with the interface as error value.

func Empty

func Empty(e error) bool

Empty check if error message is an empty string.

func Equal

func Equal(e1 error, e2 error) bool

Equal check if two errors are equal.

func New

func New(v ...interface{}) error

New return an error created on the base of a given interface.

func Prefix

func Prefix(e error, p ...interface{}) error

Prefix an error with one or a list of custom value.

func Set

func Set(e error, v ...interface{}) error

Set if error is not nil return a new error with the interface as error value.

Types

type HandlerFunc

type HandlerFunc func(error) error

type Handlers

type Handlers struct {
	// contains filtered or unexported fields
}

func Handler

func Handler(e error) *Handlers

func (*Handlers) Add

func (h *Handlers) Add(f ...HandlerFunc) error

Add a list of handlers to a new error.

func (*Handlers) Get

func (h *Handlers) Get() []HandlerFunc

Get a list of existing handler func

func (*Handlers) Loop

func (h *Handlers) Loop() error

Loop a list of handlers on an error or multiple error.

type Multiple

type Multiple struct {
	// contains filtered or unexported fields
}

func Multi

func Multi(e error) *Multiple

func (*Multiple) Add

func (m *Multiple) Add(elems ...error) error

Append multiple errors to only one.

func (*Multiple) Get

func (m *Multiple) Get() []error

Errors return a list of errors if exist.

type Recovery

type Recovery struct {
	// contains filtered or unexported fields
}

func Recover

func Recover(e *error) *Recovery

Recover set an error pointer to recover error with stack trace.

func (*Recovery) Error

func (rc *Recovery) Error()

Error set the error pointer to error message only

func (*Recovery) Stack

func (rc *Recovery) Stack()

Stack set the error pointer to stack trace only

Jump to

Keyboard shortcuts

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