errors

package
v0.0.0-...-c8a5df3 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package errors defines the error handling used by corpus.

Index

Constants

This section is empty.

Variables

View Source
var Separator = ":\n\t"

Separator is the string used to separate nested errors. By default, to make errors easier on the eye, nested errors are indented on a new line. A server may instead choose to keep each error on a single line by modifying the separator string, perhaps to ":: ".

Functions

func E

func E(args ...interface{}) error

E builds an error value from its arguments. There must be at least one argument or E panics. The type of each argument determines its meaning. If more than one argument of a given type is presented, only the last one is recorded.

The types are:

string
	The operation being performed, usually the method
	being invoked (Get, Put, etc.)
errors.Kind
	The class of error, such as permission failure.
error
	The underlying error that triggered this one.

If the error is printed, only those items that have been set to non-zero values will appear in the result.

If Kind is not specified or Other, we set it to the Kind of the underlying error.

func MarshalError

func MarshalError(err error) []byte

MarshalError marshals an arbitrary error and returns the byte slice. If the error is nil, it returns nil. It returns the argument slice unchanged if the error is nil. If the error is not an *Error, it just records the result of err.Error(). Otherwise it encodes the full Error struct.

func MarshalErrorAppend

func MarshalErrorAppend(err error, b []byte) []byte

MarshalErrorAppend marshals an arbitrary error into a byte slice. The result is appended to b, which may be nil. It returns the argument slice unchanged if the error is nil. If the error is not an *Error, it just records the result of err.Error(). Otherwise it encodes the full Error struct.

func Str

func Str(text string) error

Str returns an error that formats as the given text. It is intended to be used as the error-typed argument to the E function.

func Strf

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

Strf is equivalent to errors.Errorf, but allows clients to import only this package for all error handling.

func UnmarshalError

func UnmarshalError(b []byte) error

UnmarshalError unmarshals the byte slice into an error value. If the slice is nil or empty, it returns nil. Otherwise the byte slice must have been created by MarshalError or MarshalErrorAppend. If the encoded error was of type *Error, the returned error value will have that underlying type. Otherwise it will be just a simple value that implements the error interface.

Types

type Error

type Error struct {
	// Path is the Tapr path name of the item being accessed.
	Path tapr.PathName

	// Op is the operation being performed, usually the name of the method
	// being invoked (Get, Put, etc.).
	Op string

	// Kind is the class of error, such as permission failure,
	// or "Other" if its class is unknown or irrelevant.
	Kind Kind

	// The underlying error that triggered this one, if any.
	Err error
}

Error is the type that implements the error interface. It contains a number of fields, each of different type. An Error value may leave some values unset.

func (*Error) Error

func (e *Error) Error() string

func (*Error) MarshalAppend

func (e *Error) MarshalAppend(b []byte) []byte

MarshalAppend marshals err into a byte slice. The result is appended to b, which may be nil. It returns the argument slice unchanged if the error is nil.

func (*Error) MarshalBinary

func (e *Error) MarshalBinary() ([]byte, error)

MarshalBinary marshals its receiver into a byte slice, which it returns. It returns nil if the error is nil. The returned error is always nil.

func (*Error) UnmarshalBinary

func (e *Error) UnmarshalBinary(b []byte) error

UnmarshalBinary unmarshals the byte slice into the receiver, which must be non-nil. The returned error is always nil.

type Kind

type Kind uint8

Kind defines the kind of error this is, mostly for use by systems such as FUSE that must act differently depending on the error.

const (
	Other      Kind = iota // Unclassified error. This value is not printed in the error message.
	Invalid                // Invalid operation for this type of item.
	Permission             // Permission denied.
	IO                     // External I/O error such as network failure.
	Exist                  // Item already exists.
	NotExist               // Item does not exist.
	IsDir                  // Item is a directory.
	NotDir                 // Item is not a directory..
	NotEmpty               // Directory not empty.
	Private                // Information withheld.
	Internal               // Internal error or inconsistency.
	Transient              // A transient error.
)

Kinds of errors.

The values of the error kinds are common between both clients and servers. Do not reorder this list or remove any items since that will change their values. New items must be added only to the end.

func (Kind) String

func (k Kind) String() string

Jump to

Keyboard shortcuts

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