common

package
v0.0.0-...-c722118 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Prefix = ""
)

Functions

This section is empty.

Types

type Error

type Error struct {
	// ID returns the unique id of the error, it's needed
	// when we want to check if a specific error returned
	// but the `Error() string` value is not the same because the error may be dynamic
	// by a `Format` call.
	ID string `json:"id"`
	// The message of the error.
	Message string `json:"message"`
	// Apennded is true whenever it's a child error.
	Appended bool `json:"appended"`
	// Stack returns the list of the errors that are shown at `Error() string`.
	Stack []Error `json:"stack"` // filled on AppendX.
}

func NewErrors

func NewErrors(errMsg string) Error

New creates and returns an Error with a pre-defined user output message all methods below that doesn't accept a pointer receiver because actually they are not changing the original message

func NewFromErr

func NewFromErr(err error) *Error

NewFromErr same as `New` but pointer for nil checks without the need of the `Return()` function.

func (Error) Append

func (e Error) Append(format string, a ...interface{}) Error

Append adds a message to the predefined error message and returns a new error it does NOT change the original error's message

func (Error) AppendErr

func (e Error) AppendErr(err error) Error

AppendErr adds an error's message to the predefined error message and returns a new error. it does NOT change the original error's message

func (Error) AppendInline

func (e Error) AppendInline(format string, a ...interface{}) Error

AppendInline appends an error to the stack. It doesn't try to append a new line if needed.

func (Error) Empty

func (e Error) Empty() bool

Empty returns true if the "e" Error has no message on its stack.

func (Error) Equal

func (e Error) Equal(to error) bool

Equal returns true if "e" and "to" are matched, by their IDs if it's a core/errors type otherwise it tries to match their error messages. It will always returns true if the "to" is a children of "e" or the error messages are exactly the same, otherwise false.

func (Error) Error

func (e Error) Error() string

Error returns the message of the actual error implements the error

func (Error) Format

func (e Error) Format(a ...interface{}) Error

Format returns a formatted new error based on the arguments it does NOT change the original error's message

func (Error) HasStack

func (e Error) HasStack() bool

HasStack returns true if the Error instance is created using Append/AppendInline/AppendErr funcs.

func (Error) Ignore

func (e Error) Ignore(err error) error

Ignore will ignore the "err" and return nil.

func (Error) NotEmpty

func (e Error) NotEmpty() bool

NotEmpty returns true if the "e" Error has got a non-empty message on its stack.

func (Error) Panic

func (e Error) Panic()

Panic output the message and after panics.

func (Error) Panicf

func (e Error) Panicf(args ...interface{})

Panicf output the formatted message and after panics.

func (Error) String

func (e Error) String() string

String returns the error message

func (Error) With

func (e Error) With(err error) error

With does the same thing as Format but it receives an error type which if it's nil it returns a nil error.

Jump to

Keyboard shortcuts

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