Documentation ¶
Index ¶
- Variables
- func PrintAndReturnErrors(err error, printer func(string, ...interface{})) error
- type Error
- func (e Error) Append(format string, a ...interface{}) Error
- func (e Error) AppendErr(err error) Error
- func (e Error) AppendInline(format string, a ...interface{}) Error
- func (e Error) Empty() bool
- func (e Error) Equal(to error) bool
- func (e Error) Error() string
- func (e Error) Format(a ...interface{}) Error
- func (e Error) HasStack() bool
- func (e Error) Ignore(err error) error
- func (e Error) NotEmpty() bool
- func (e Error) Panic()
- func (e Error) Panicf(args ...interface{})
- func (e Error) String() string
- func (e Error) With(err error) error
- type Reporter
- func (r *Reporter) Add(format string, a ...interface{}) bool
- func (r *Reporter) AddErr(err error) bool
- func (r *Reporter) Describe(format string, err error)
- func (r *Reporter) Error() string
- func (r *Reporter) PrintStack(printer func(string, ...interface{})) error
- func (r *Reporter) Return() error
- func (r *Reporter) Stack() []Error
- type StackError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var (
// Prefix the error prefix, applies to each error's message.
Prefix = ""
)
Functions ¶
func PrintAndReturnErrors ¶
PrintAndReturnErrors prints the "err" to the given "printer", printer will be called multiple times if the "err" is a StackError, where it contains more than one error.
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. }
Error holds the error message, this message never really changes
func New ¶
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 ¶
NewFromErr same as `New` but pointer for nil checks without the need of the `Return()` function.
func (Error) Append ¶
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 ¶
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 ¶
AppendInline appends an error to the stack. It doesn't try to append a new line if needed.
func (Error) Equal ¶
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) Format ¶
Format returns a formatted new error based on the arguments it does NOT change the original error's message
func (Error) HasStack ¶
HasStack returns true if the Error instance is created using Append/AppendInline/AppendErr funcs.
func (Error) NotEmpty ¶
NotEmpty returns true if the "e" Error has got a non-empty message on its stack.
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter is a helper structure which can stack errors and prints them to a printer of func(string).
func (*Reporter) Add ¶
Add adds a formatted message as an error to the error stack.
Returns true if this "err" is not nil and it's added to the reporter's stack.
func (*Reporter) AddErr ¶
AddErr adds an error to the error stack. if "err" is a StackError then each of these errors will be printed as individual.
Returns true if this "err" is not nil and it's added to the reporter's stack.
func (*Reporter) PrintStack ¶
PrintStack prints all the errors to the given "printer". Returns itself in order to be used as printer and return the full error in the same time.
type StackError ¶
StackError contains the Stack method.