errors

package module
v1.1.18 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2020 License: MIT Imports: 6 Imported by: 4

README

errors

Build Status GitHub tag (latest SemVer) GoDoc Go Report Card codecov

Nestable errors for golang dev (both go1.13+ and lower now).

Take a look at: https://play.golang.org/p/P0kk4NhAbd3

Import

import "github.com/hedzr/errors"

Sometimes you need ignore gosumdb error '410 Gone'

export GONOSUMDB="github.com/hedzr/errors,$GONOSUMDB"
# Or
export GOSUMDB=off

For more information, see also: https://github.com/golang/go/issues/35164

Enh for go errors

Adapted for golang 1.13+
  • Is(err, target) bool
  • As(err, target) bool
  • Unwrap(err) error
func TestIsAs(t *testing.T) {
	var err error
	err = errors.New("something").Attach(errBug1, errBug2).Nest(errBug3, errBug4).Msg("anything")
	if errors.Is(err, errBug1) {
		fmt.Println(" err ==IS== errBug1")
	}
	if errors.Is(err, errBug3) {
		fmt.Println(" err ==IS== errBug3")
	}

	err2 := errors.NewWithError(io.ErrShortWrite).Nest(io.EOF)
	if errors.Is(err2, io.ErrShortWrite) {
		fmt.Println(" err2 ==IS== io.ErrShortWrite")
	}
	if errors.Is(err2, io.EOF) {
		fmt.Println(" err2 ==IS== io.EOF")
	}
}

since v1.1.7, we works for golang 1.12 and lower.

Replace stdlib errors

In most cases, smoothly migrated from stdlib errors is possible: just replace the import statements.

Adapted and enhanced:

  • New(fmt, ...)

More extendings:

  • NewTemplate(tmpl)
  • NewWithError(errs...)
  • NewCodedError(code, errs...)
  • Wrap(err, format, args...)
enhancements for go errors
  1. Walkable: errors.Walk(fn)
  2. Ranged: errors.Range(fn)
  3. Tests:
    1. CanWalk(err), CanRange(err), CanIs(err), CanAs(err), CanUnwrap(err)
    2. Equal(err, code), IsAny(err, codes...), IsBoth(err, codes...),
    3. TextContains(err, text)
    4. HasAttachedErrors(err)
    5. HasWrappedError(err)
    6. HasInnerErrors(err)
  4. Attach(err, errs...), Nest(err, errs...)
  5. DumpStacksAsString(allRoutines bool) string

Err Objects

ExtErr object
error with message
var (
  errBug1 = errors.New("bug 1")
  errBug2 = errors.New("bug 2, %v, %d", []string{"a","b"}, 5)
  errBug3 = errors.New("bug 3")
)

func main() {
  err := errors.New("something grouped").Attach(errBug1, errBug2)
  err1 := errors.New("something nested").Nest(errBug1, errBug2)
  err2 := errors.New(errBug3)

  err2.Msg("a %d", 1)

  log.Println(err, err1, err2)
}
Attachable, and Nestable (Wrapable)
Attach

Attach(...) can package a group of errors into the receiver ExtErr.

For example:

// or: errors.New("1").Attach(io.EOF,io.ErrShortWrite, io.ErrShortBuffer)
err := errors.New("1").Attach(io.EOF).Attach(io.ErrShortWrite).Attach(io.ErrShortBuffer)
fmt.Println(err)
fmt.Printf("%#v\n", err)
// result:
// 1, EOF, short write, short buffer
// &errors.ExtErr{inner:(*errors.ExtErr)(nil), errs:[]error{(*errors.errorString)(0xc000042040), (*errors.errorString)(0xc000042020), (*errors.errorString)(0xc000042030)}, msg:"1", tmpl:""}

The structure looks like:

&ExtErr{
  msg: "1",
  errs: [
    io.EOF,
    io.ErrShortWrite,
    io.ErrShortBuffer
  ],
}
Nest

Nest(...) could wrap the errors as a deep descendant child ExtErr of the receiver ExtError.

For example:

err := errors.New("1").Nest(io.EOF).Nest(io.ErrShortWrite).Nest(io.ErrShortBuffer)
fmt.Println(err)
fmt.Printf("%#v\n", err)
// result:
// 1, EOF[error, short write[error, short buffer]]
// &errors.ExtErr{inner:(*errors.ExtErr)(0x43e2e0), errs:[]error{(*errors.errorString)(0x40c040)}, msg:"1", tmpl:""}

To make it clear:

&ExtErr{
  msg: "1",
  inner: &ExtErr {
    inner: &ExtErr {
      errs: [
        io.ErrShortBuffer
      ],
    },
    errs: [
      io.ErrShortWrite,
    ],
  },
  errs: [
    io.EOF,
  ],
}
Template

You could put a string template into both ExtErr and CodedErr, and format its till using.

For example:

const (
	BUG1004 errors.Code = -1004
	BUG1005 errors.Code = -1005
)

var (
	eb1  = errors.NewTemplate("xxbug 1, cause: %v")
	eb11 = errors.New("").Msg("first, %v", "ok").Template("xxbug11, cause")
	eb2  = errors.NewCodedError(BUG1004).Template("xxbug4, cause: %v")
	eb3  = errors.NewCodedError(BUG1005).Template("xxbug5, cause: none")
	eb31 = errors.NewCodedError(BUG1004).Msg("first, %v", "ok").Template("xxbug4.31, cause: %v")
	eb4  = errors.NewCodedError(BUG1005).Template("xxbug54, cause: none")
)

func init() {
	BUG1004.Register("BUG1004")
	BUG1005.Register("BUG1005")
}

func TestAll(t *testing.T) {
	err = eb1.Format("resources exhausted")
	t.Log(err)
}

Yet another one:

const (
	ErrNoNotFound errors.Code = -9710
)

var (
	ErrNotFound  = errors.NewCodedError(ErrNoNotFound).Template("'%v' not found")
	ErrNotFound2 = errors.NewCodedError(-9711).Template("'%v' not found")
)

func init() {
	ErrNoNotFound.Register("Not Found")
	errors.Code(-9711).Register("Not Found 2")
}

// ...
return ErrNoNotFound.Format(filename)
CodedErr object
error with a code number
var (
  errNotFound = errors.NewCodedError(errors.NotFound)
  errNotFoundMsg = errors.NewCodedError(errors.NotFound).Msg("not found")
)
Predefined error codes

The builtin error codes are copied from Google gRPC codes but negatived.

The numbers -1..-999 are reserved.

register your error codes:

The user-defined error codes (must be < -1000, or > 0) could be registered into errors.Code with its codename.

For example (run it at play-ground: https://play.golang.org/p/ifUvABaPEoJ):

package main

import (
	"fmt"
	"github.com/hedzr/errors"
	"io"
)

const (
	BUG1001 errors.Code = 1001
	BUG1002 errors.Code = 1002
)

var (
	errBug1001 = errors.NewCodedError(BUG1001).Msg("something is wrong").Attach(io.EOF)
)

func init() {
	BUG1001.Register("BUG1001")
	BUG1002.Register("BUG1002")
}

func main() {
	fmt.Println(BUG1001.String())
	fmt.Println(BUG1001.Number())
	fmt.Println(errBug1001)
	fmt.Println(errBug1001.Equal(BUG1001))
	fmt.Println(errBug1001.EqualRecursive(BUG1001))
}

Result:

BUG1001
001001|BUG1001|something is wrong, EOF

Extending ExtErr or CodedErr

You might want to extend the ExtErr/CodedErr with more fields, just like CodedErr.code.

For better cascaded calls, it might be crazy had you had to override some functions: Template, Format, Msg, Attach, and Nest. But no more worries, simply copy them from CodedErr and correct the return type for yourself.

For example:

// newError formats a ErrorForCmdr object
func newError(ignorable bool, sourceTemplate *ErrorForCmdr, args ...interface{}) *ErrorForCmdr {
	e := sourceTemplate.Format(args...)
	e.Ignorable = ignorable
	return e
}

// newErrorWithMsg formats a ErrorForCmdr object
func newErrorWithMsg(msg string, inner error) *ErrorForCmdr {
	return newErr(msg).Attach(inner)
}

func newErr(msg string, args ...interface{}) *ErrorForCmdr {
	return &ErrorForCmdr{ExtErr: *errors.New(msg, args...)}
}

func newErrTmpl(tmpl string) *ErrorForCmdr {
	return &ErrorForCmdr{ExtErr: *errors.NewTemplate(tmpl)}
}

func (e *ErrorForCmdr) Error() string {
	var buf bytes.Buffer
	buf.WriteString(fmt.Sprintf("%v|%s", e.Ignorable, e.ExtErr.Error()))
	return buf.String()
}

// Template setup a string format template.
// Coder could compile the error object with formatting args later.
//
// Note that `ExtErr.Template()` had been overrided here
func (e *ErrorForCmdr) Template(tmpl string) *ErrorForCmdr {
	_ = e.ExtErr.Template(tmpl)
	return e
}

// Format compiles the final msg with string template and args
//
// Note that `ExtErr.Template()` had been overridden here
func (e *ErrorForCmdr) Format(args ...interface{}) *ErrorForCmdr {
	_ = e.ExtErr.Format(args...)
	return e
}

// Msg encodes a formattable msg with args into ErrorForCmdr
//
// Note that `ExtErr.Template()` had been overridden here
func (e *ErrorForCmdr) Msg(msg string, args ...interface{}) *ErrorForCmdr {
	_ = e.ExtErr.Msg(msg, args...)
	return e
}

// Attach attaches the nested errors into ErrorForCmdr
//
// Note that `ExtErr.Template()` had been overridden here
func (e *ErrorForCmdr) Attach(errors ...error) *ErrorForCmdr {
	_ = e.ExtErr.Attach(errors...)
	return e
}

// Nest attaches the nested errors into ErrorForCmdr
//
// Note that `ExtErr.Template()` had been overridden here
func (e *ErrorForCmdr) Nest(errors ...error) *ErrorForCmdr {
	_ = e.ExtErr.Nest(errors...)
	return e
}

A sample here: https://github.com/hedzr/errors-for-mqtt

More

strings helpers:

  • Left(s, length)
  • Right(s, length)
  • LeftPad(s, pad, width)

LICENSE

MIT

Documentation

Overview

Package errors defines the generic error codes, nestable ExtErr object.

Index

Examples

Constants

View Source
const (
	// OK is returned on success.
	OK Code = 0

	// Canceled indicates the operation was canceled (typically by the caller).
	Canceled Code = -1

	// Unknown error. An example of where this error may be returned is
	// if a Status value received from another address space belongs to
	// an error-space that is not known in this address space. Also
	// errors raised by APIs that do not return enough error information
	// may be converted to this error.
	Unknown Code = -2

	// InvalidArgument indicates client specified an invalid argument.
	// Note that this differs from FailedPrecondition. It indicates arguments
	// that are problematic regardless of the state of the system
	// (e.g., a malformed file name).
	InvalidArgument Code = -3

	// DeadlineExceeded means operation expired before completion.
	// For operations that change the state of the system, this error may be
	// returned even if the operation has completed successfully. For
	// example, a successful response from a server could have been delayed
	// long enough for the deadline to expire.
	//
	// = HTTP 408 Timeout
	DeadlineExceeded Code = -4

	// NotFound means some requested entity (e.g., file or directory) was
	// not found.
	//
	// = HTTP 404
	NotFound Code = -5

	// AlreadyExists means an attempt to create an entity failed because one
	// already exists.
	AlreadyExists Code = -6

	// PermissionDenied indicates the caller does not have permission to
	// execute the specified operation. It must not be used for rejections
	// caused by exhausting some resource (use ResourceExhausted
	// instead for those errors). It must not be
	// used if the caller cannot be identified (use Unauthenticated
	// instead for those errors).
	PermissionDenied Code = -7

	// ResourceExhausted indicates some resource has been exhausted, perhaps
	// a per-user quota, or perhaps the entire file system is out of space.
	ResourceExhausted Code = -8

	// FailedPrecondition indicates operation was rejected because the
	// system is not in a state required for the operation's execution.
	// For example, directory to be deleted may be non-empty, an rmdir
	// operation is applied to a non-directory, etc.
	//
	// A litmus test that may help a service implementor in deciding
	// between FailedPrecondition, Aborted, and Unavailable:
	//  (a) Use Unavailable if the client can retry just the failing call.
	//  (b) Use Aborted if the client should retry at a higher-level
	//      (e.g., restarting a read-modify-write sequence).
	//  (c) Use FailedPrecondition if the client should not retry until
	//      the system state has been explicitly fixed. E.g., if an "rmdir"
	//      fails because the directory is non-empty, FailedPrecondition
	//      should be returned since the client should not retry unless
	//      they have first fixed up the directory by deleting files from it.
	//  (d) Use FailedPrecondition if the client performs conditional
	//      REST Get/Update/Delete on a resource and the resource on the
	//      server does not match the condition. E.g., conflicting
	//      read-modify-write on the same resource.
	FailedPrecondition Code = -9

	// Aborted indicates the operation was aborted, typically due to a
	// concurrency issue like sequencer check failures, transaction aborts,
	// etc.
	//
	// See litmus test above for deciding between FailedPrecondition,
	// Aborted, and Unavailable.
	Aborted Code = -10

	// OutOfRange means operation was attempted past the valid range.
	// E.g., seeking or reading past end of file.
	//
	// Unlike InvalidArgument, this error indicates a problem that may
	// be fixed if the system state changes. For example, a 32-bit file
	// system will generate InvalidArgument if asked to read at an
	// offset that is not in the range [0,2^32-1], but it will generate
	// OutOfRange if asked to read from an offset past the current
	// file size.
	//
	// There is a fair bit of overlap between FailedPrecondition and
	// OutOfRange. We recommend using OutOfRange (the more specific
	// error) when it applies so that callers who are iterating through
	// a space can easily look for an OutOfRange error to detect when
	// they are done.
	OutOfRange Code = -11

	// Unimplemented indicates operation is not implemented or not
	// supported/enabled in this service.
	Unimplemented Code = -12

	// Internal errors. Means some invariants expected by underlying
	// system has been broken. If you see one of these errors,
	// something is very broken.
	Internal Code = -13

	// Unavailable indicates the service is currently unavailable.
	// This is a most likely a transient condition and may be corrected
	// by retrying with a backoff. Note that it is not always safe to retry
	// non-idempotent operations.
	//
	// See litmus test above for deciding between FailedPrecondition,
	// Aborted, and Unavailable.
	Unavailable Code = -14

	// DataLoss indicates unrecoverable data loss or corruption.
	DataLoss Code = -15

	// Unauthenticated indicates the request does not have valid
	// authentication credentials for the operation.
	//
	// = HTTP 401 Unauthorized
	Unauthenticated Code = -16

	// RateLimited indicates some flow control algorithm is running and applied.
	// = HTTP Code 429
	RateLimited = -17

	// BadRequest generates a 400 error.
	// = HTTP 400
	BadRequest = -18

	// Conflict generates a 409 error.
	// = hTTP 409
	Conflict = -19

	// Forbidden generates a 403 error.
	Forbidden = -20

	// InternalServerError generates a 500 error.
	InternalServerError = -21

	// MethodNotAllowed generates a 405 error.
	MethodNotAllowed = -22

	// MinErrorCode is the lower bound
	MinErrorCode = -1000
)
View Source
const (
	// AppName const
	AppName = "errors"
	// Version const
	Version = "1.1.18"
	// VersionInt const
	VersionInt = 0x010118
)

Variables

This section is empty.

Functions

func As added in v1.1.0

func As(err error, target interface{}) bool

As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true.

The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.

An error matches target if the error's concrete value is assignable to the value pointed to by target, or if the error has a method As(interface{}) bool such that As(target) returns true. In the latter case, the As method is responsible for setting target.

As will panic if target is not a non-nil pointer to either a type that implements error, or to any interface type. As returns false if err is nil.

Example
package main

import (
	"fmt"
	"github.com/hedzr/errors"
	"os"
)

func main() {
	if _, err := os.Open("non-existing"); err != nil {
		var pathError *os.PathError
		if errors.As(err, &pathError) {
			fmt.Println("Failed at path:", pathError.Path)
		} else {
			fmt.Println(err)
		}
	}

}
Output:

Failed at path: non-existing

func Attach added in v1.1.9

func Attach(err error, errs ...error)

Attach attaches the errors into `err`

func CanAs added in v1.1.8

func CanAs(err error) (ok bool)

CanAs tests if err is as-able

func CanIs added in v1.1.8

func CanIs(err error) (ok bool)

CanIs tests if err is is-able

func CanRange added in v1.1.8

func CanRange(err error) (ok bool)

CanRange tests if err is range-able

func CanUnwrap added in v1.1.8

func CanUnwrap(err error) (ok bool)

CanUnwrap tests if err is unwrap-able

func CanWalk added in v1.1.8

func CanWalk(err error) (ok bool)

CanWalk tests if err is walkable

func DumpStacksAsString added in v1.1.11

func DumpStacksAsString(allRoutines bool) string

DumpStacksAsString returns stack tracing information like debug.PrintStack()

func Equal added in v1.1.9

func Equal(err error, code Code) bool

Equal tests if code number presented recursively

func HasAttachedErrors added in v1.1.11

func HasAttachedErrors(err error) (yes bool)

HasAttachedErrors detects if attached errors present

func HasInnerErrors added in v1.1.11

func HasInnerErrors(err error) (yes bool)

HasInnerErrors detects if nested or attached errors present

func HasWrappedError added in v1.1.11

func HasWrappedError(err error) (yes bool)

HasWrappedError detects if nested or wrapped errors present

nested error: ExtErr.inner wrapped error: fmt.Errorf("... %w ...", err)

func Is added in v1.1.0

func Is(err, target error) bool

Is reports whether any error in err's chain matches target.

The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.

An error is considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.

func IsAny added in v1.1.9

func IsAny(err error, code ...Code) bool

IsAny tests if any codes presented

func IsBoth added in v1.1.9

func IsBoth(err error, code ...Code) bool

IsBoth tests if all codes presented

func Left added in v1.1.8

func Left(s string, length int) string

Left returns the left `length` substring of `s`. Left returns the whole source string `s` if its length is larger than `length`

Left("12345",3) => "123"

func LeftPad added in v1.1.8

func LeftPad(s string, pad rune, width int) string

LeftPad adds the leading char `pad` to `s`, and truncate it to the length `width`.

LeftPad("89", '0', 6) => "000089"

LeftPad returns an empty string "" if width is negative or zero. LeftPad returns the source string `s` if its length is larger than `width`.

func Nest added in v1.1.9

func Nest(err error, errs ...error)

Nest wraps/nests the errors into `err`

func Range added in v1.1.8

func Range(err error, fn func(err error) (stop bool))

Range can walk the inner/attached errors inside err

func Right(s string, length int) string

Right returns the right `length` substring of `s`. Right returns the whole source string `s` if its length is larger than `length`

Right("12345",3) => "345"

func TextContains added in v1.1.11

func TextContains(err error, text string) bool

TextContains test if a text fragment is included by err

func Unwrap added in v1.1.0

func Unwrap(err error) error

Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.

func Walk added in v1.1.8

func Walk(err error, fn func(err error) (stop bool))

Walk will walk all inner and nested error objects inside err

Types

type Code

type Code int32

A Code is an signed 32-bit error code copied from gRPC spec but negatived.

func (Code) New added in v1.1.8

func (c Code) New(msg string, args ...interface{}) *CodedErr

New create a new *CodedErr object

func (Code) Register

func (c Code) Register(codeName string) (errno Code)

Register register a code and its token string for using later

func (Code) String

func (c Code) String() string

String for stringer interface

type CodedErr

type CodedErr struct {
	ExtErr
	// contains filtered or unexported fields
}

CodedErr adds a error code

func NewCodedError added in v1.1.0

func NewCodedError(code Code, errs ...error) *CodedErr

NewCodedError error object with nested errors

func (*CodedErr) Attach added in v1.1.0

func (e *CodedErr) Attach(errors ...error) *CodedErr

Attach attaches the nested errors into CodedErr

Note that `ExtErr.Template()` had been overridden here

func (*CodedErr) AttachIts added in v1.1.9

func (e *CodedErr) AttachIts(errors ...error)

AttachIts attaches the nested errors into CodedErr

func (*CodedErr) Code

func (e *CodedErr) Code(code Code) *CodedErr

Code put another code into CodedErr

func (*CodedErr) Equal added in v1.1.8

func (e *CodedErr) Equal(code Code) bool

Equal compares with code

func (*CodedErr) EqualRecursive added in v1.1.8

func (e *CodedErr) EqualRecursive(code Code) bool

EqualRecursive compares with code

func (*CodedErr) Error

func (e *CodedErr) Error() string

Error for stringer interface

func (*CodedErr) Format added in v1.1.1

func (e *CodedErr) Format(args ...interface{}) *CodedErr

Format compiles the final msg with string template and args

Note that `ExtErr.Template()` had been overridden here

func (*CodedErr) HasAttachedErrors added in v1.1.11

func (e *CodedErr) HasAttachedErrors() bool

HasAttachedErrors tests if any errors attached (nor nested) to `e` or not

func (*CodedErr) IsAny added in v1.1.9

func (e *CodedErr) IsAny(code ...Code) bool

IsAny tests if any codes presented

func (*CodedErr) IsBoth added in v1.1.9

func (e *CodedErr) IsBoth(code ...Code) bool

IsBoth tests if all codes presented

func (*CodedErr) Msg added in v1.1.0

func (e *CodedErr) Msg(msg string, args ...interface{}) *CodedErr

Msg encodes a formattable msg with args into ExtErr

Note that `ExtErr.Template()` had been overridden here

func (*CodedErr) Nest added in v1.1.0

func (e *CodedErr) Nest(errors ...error) *CodedErr

Nest attaches the nested errors into CodedErr

Note that `ExtErr.Template()` had been overridden here

func (*CodedErr) NestIts added in v1.1.9

func (e *CodedErr) NestIts(errors ...error)

NestIts attaches the nested errors into CodedErr

func (*CodedErr) NoCannedError added in v1.1.9

func (e *CodedErr) NoCannedError() bool

NoCannedError detects mqttError object is not an error or not an canned-error (inners is empty)

func (*CodedErr) Number added in v1.1.8

func (e *CodedErr) Number() Code

Number returns the code number

func (*CodedErr) Template added in v1.1.1

func (e *CodedErr) Template(tmpl string) *CodedErr

Template setup a string format template. Coder could compile the error object with formatting args later.

Note that `ExtErr.Template()` had been overrided here

type ExtErr

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

ExtErr is a nestable error object

func New

func New(format string, args ...interface{}) *ExtErr

New ExtErr error object with message and allows attach more nested errors

func NewTemplate added in v1.1.1

func NewTemplate(tmpl string) *ExtErr

NewTemplate ExtErr error object with string template and allows attach more nested errors

func NewWithError

func NewWithError(errs ...error) *ExtErr

NewWithError ExtErr error object with nested errors

func Wrap added in v1.1.15

func Wrap(err error, format string, args ...interface{}) *ExtErr

Wrap attaches an error object `err` into ExtErr.

With go official model, the behavior is: fmt.Sprintf("...%w...", err) In our model, `err` will be attached/wrapped into an ExtErr object.

func (*ExtErr) As added in v1.1.3

func (e *ExtErr) As(target interface{}) bool

As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true.

func (*ExtErr) Attach added in v1.1.0

func (e *ExtErr) Attach(errors ...error) *ExtErr

Attach attaches a group of errors into ExtErr

func (*ExtErr) AttachIts added in v1.1.9

func (e *ExtErr) AttachIts(errors ...error)

AttachIts attaches the nested errors into ExtErr

func (*ExtErr) Error

func (e *ExtErr) Error() string

func (*ExtErr) Format added in v1.1.1

func (e *ExtErr) Format(args ...interface{}) *ExtErr

Format compiles the final msg with string template and args

func (*ExtErr) GetAttachedErrors added in v1.1.11

func (e *ExtErr) GetAttachedErrors() []error

GetAttachedErrors returns e.errs member (attached errors)

func (*ExtErr) GetMsgString added in v1.1.8

func (e *ExtErr) GetMsgString() string

GetMsgString returns e.msg member

func (*ExtErr) GetNestedError added in v1.1.11

func (e *ExtErr) GetNestedError() *ExtErr

GetNestedError returns e.inner member (nested errors)

func (*ExtErr) GetTemplateString added in v1.1.8

func (e *ExtErr) GetTemplateString() string

GetTemplateString returns e.tmpl member

func (*ExtErr) HasAttachedErrors added in v1.1.11

func (e *ExtErr) HasAttachedErrors() bool

HasAttachedErrors tests if any errors attached (nor nested) to `e` or not

func (*ExtErr) Is added in v1.1.3

func (e *ExtErr) Is(err error) bool

Is reports whether any error in err's chain matches target.

func (*ExtErr) Msg added in v1.1.0

func (e *ExtErr) Msg(msg string, args ...interface{}) *ExtErr

Msg encodes a formattable msg with args into ExtErr

func (*ExtErr) Nest added in v1.1.0

func (e *ExtErr) Nest(errors ...error) *ExtErr

Nest attaches the nested errors into ExtErr

func (*ExtErr) NestIts added in v1.1.9

func (e *ExtErr) NestIts(errors ...error)

NestIts attaches the nested errors into ExtErr

func (*ExtErr) NoCannedError added in v1.1.9

func (e *ExtErr) NoCannedError() bool

NoCannedError detects mqttError object is not an error or not an canned-error (inners is empty)

func (*ExtErr) Range added in v1.1.8

func (e *ExtErr) Range(fn func(err error) (stop bool))

Range can walk the inner/attached errors inside e

func (*ExtErr) Template added in v1.1.1

func (e *ExtErr) Template(tmpl string) *ExtErr

Template setup a string format template. Coder could compile the error object with formatting args later.

func (*ExtErr) Unwrap added in v1.1.0

func (e *ExtErr) Unwrap() error

Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.

func (*ExtErr) Walk added in v1.1.8

func (e *ExtErr) Walk(fn func(err error) (stop bool))

Walk will walk all inner/attached and nested error objects inside e

type Ranged added in v1.1.8

type Ranged interface {
	Range(fn func(err error) (stop bool))
}

Ranged interface

type Walkable added in v1.1.8

type Walkable interface {
	Walk(fn func(err error) (stop bool))
}

Walkable interface

Jump to

Keyboard shortcuts

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