errhandler

package
v0.0.0-...-cfd1018 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package errhandler provide utility to adding error handling.

With is the function to handle the error, this function must be called with defer.

for example:

import (
	"github.com/payfazz/go-errors"
	"github.com/payfazz/go-errors/errhandler"
)

func main() {
	defer errhandler.With(nil)

	something, err := getSomething()
	errhandler.Check(errors.Wrap(err)) // using Wrap so we got the stack trace

	something2, err := getSomething2(something)
	if err != nil {
		errhandler.Check(errors.NewWithCause("getSomething2 is failing", err))
	}
}

NOTE

please note that With adding some overhead, do not use it frequently, you should use golang idiom:

if err != nil {
	return errors.Wrap(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CatchAndSet

func CatchAndSet(err *error) func(error)

CatchAndSet create function to catch error and set it to err

func Check

func Check(err error)

Check the error

func UnwrapUnhandledError

func UnwrapUnhandledError(err error) error

UnwrapUnhandledError will unwrap the wrapper error used by errhandler.With to the original error

This may be needed if you want to doing recover() manualy in the defer

func With

func With(f func(error))

With will handle the error using f when Check is triggering the error

if f is nil, default handler is to print error to stderr and exit with error code 1.

Types

This section is empty.

Jump to

Keyboard shortcuts

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