errors

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2021 License: MIT Imports: 4 Imported by: 15

README

see https://godoc.org/github.com/payfazz/go-errors

v1 is not maintaned anymore, please use v2

Documentation

Overview

Package errors provide utility for wrapping error.

The wrapped error will have more information (stack trace and other error that cause the error).

NOTE: v1 is not maintaned anymore, please use v2

Index

Constants

View Source
const DefaultDeep = 20

DefaultDeep is the default deep when generating stack trace

Variables

This section is empty.

Functions

func ErrorWithCauseF

func ErrorWithCauseF(cause error, f string, v ...interface{}) error

ErrorWithCauseF is same with like ErrorF, but you can spesify the error cause

func Errorf

func Errorf(f string, v ...interface{}) error

Errorf return an Error with text according to a format specifier.

Format as specified by fmt.Sprintf

func Format

func Format(err error) string

Format representation of the Error, including stack trace.

Use err.Error() if you want to get just the error string

func FormatWithDeep

func FormatWithDeep(err error, deep int) string

FormatWithDeep representation of the Error, including stack trace with specified deep.

Use err.Error() if you want to get just the error string

func Ignore

func Ignore(err error)

Ignore the error.

func InErrorChain

func InErrorChain(err error, data interface{}) bool

InErrorChain will return true if the data is exists in error chain

func New

func New(data interface{}) error

New return an Error with the given data.

func NewWithCause

func NewWithCause(data interface{}, err error) error

NewWithCause is same with New, but it also indicate that this Error is caused by err.

func NewWithCauseAndDeep

func NewWithCauseAndDeep(data interface{}, err error, deep int) error

NewWithCauseAndDeep is same with NewWithCause, but with specified stack deep

func PrintTo

func PrintTo(p interface{ Print(...interface{}) }, err error)

PrintTo print formated error p

func RootCause

func RootCause(err error) error

RootCause return the root cause of the error

func Walk

func Walk(err error, fn func(*Error) bool) bool

Walk is helper for walk the error chains.

Walk will return true if fn is called at least once

Walk will walk the chains as long fn return true

func Wrap

func Wrap(err error) error

Wrap the err, if err is nil, then return nil

func WrapWithDeep

func WrapWithDeep(err error, deep int) error

WrapWithDeep is same with Wrap, but with specified stack deep

Types

type Error

type Error struct {
	// Data is arbitrary data attached to this error
	Data interface{}

	// Cause of this error
	Cause error

	// StackTrace where this error generated
	StackTrace []trace.Location
}

Error represent the wrapped error

all error returned from New*, Errorf, Wrap will have type *Error

func (*Error) Error

func (e *Error) Error() string

Error from error interface

will return the error message

Directories

Path Synopsis
Package trace provide utility to get stack trace.
Package trace provide utility to get stack trace.

Jump to

Keyboard shortcuts

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