errors

package
v0.0.0-...-975a9ff Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertionErrorf

func AssertionErrorf(format string, args ...interface{}) error

func CombineErrs

func CombineErrs(msg string, code ErrCode, errs ...error) error

CombineErrs returns an error that wraps all the non-nil errors passed to it. If all errors are nil, returns nil. If there's only one non-nil error, returns that error without wrapping. Else, returns an error with the message and code as passed, with the cause set to an error that contains all the non-nil errors and for which Error() returns the concatenation of all their messages.

func ErrorWithCauseChain

func ErrorWithCauseChain(err error) string

ErrorWithCauseChain formats err and all its causes if it's an *Err, else returns err.Error().

func Errorf

func Errorf(code ErrCode, format string, args ...interface{}) error

func HasErrCode

func HasErrCode(err error, code ErrCode) bool

HasErrCode returns true if err is an *Err and err.Code == code.

func WrapErrf

func WrapErrf(cause error, format string, args ...interface{}) error

WrapErrf returns an *Err that wraps another *Err and has the same ErrCode. Panics if cause is not an *Err.

To wrap generic errors, use WrapErrorf.

func WrapErrorf

func WrapErrorf(cause error, code ErrCode, format string, args ...interface{}) error

WrapErrorf returns an *Err that wraps another arbitrary error with an ErrCode and a message.

If cause is nil, returns nil, so you can use it like

return util.WrapErrorf(DoSomethingDangerous(), util.NetworkError, "well that didn't work")

If cause is known to be of type *Err, use WrapErrf.

Types

type Err

type Err struct {
	// Code is the high-level "type" of error.
	Code ErrCode
	// Message is a human-readable description of the error.
	Message string
	// Details is optional, and can be used to associate any auxiliary data with an error.
	Details interface{}
	// Cause is optional, and points to the more specific error that caused this one.
	Cause error
}

Err is the implementation of error that all goadb functions return.

Best Practice

External errors should be wrapped using WrapErrorf, as soon as they are known about.

Intermediate code should pass *Errs up until they will be returned outside the library. Errors should *not* be wrapped at every return site.

Just before returning an *Err outside the library, it can be wrapped again, preserving the ErrCode (e.g. with WrapErrf).

func (*Err) Error

func (err *Err) Error() string

type ErrCode

type ErrCode byte

Keep this in sync with ../error.go.

const (
	AssertionError ErrCode = iota
	ParseError
	// The server was not available on the requested port.
	ServerNotAvailable
	// General network error communicating with the server.
	NetworkError
	// The connection to the server was reset in the middle of an operation. Server probably died.
	ConnectionResetError
	// The server returned an error message, but we couldn't parse it.
	AdbError
	// The server returned a "device not found" error.
	DeviceNotFound
	// Tried to perform an operation on a path that doesn't exist on the device.
	FileNoExistError
)

func (ErrCode) String

func (i ErrCode) String() string

Jump to

Keyboard shortcuts

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