Documentation ¶
Overview ¶
Package errors contains the error handling used by eventdb. It is largely inspired by (and contains code from) the upspin.io/errors package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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.
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 Errorf ¶
Errorf is equivalent to fmt.Errorf, but allows clients to import only this package for all error handling.
func Is ¶
Is reports whether err is an *Error of the given Kind. If err is nil then Is returns false.
func Match ¶
Match compares its two error arguments. It can be used to check for expected errors in tests. Both arguments must have underlying type *Error or Match will return false. Otherwise it returns true iff every non-zero element of the first error is equal to the corresponding element of the second. If the Err field is a *Error, Match recurs on that field; otherwise it compares the strings returned by the Error methods. Elements that are in the second argument but not present in the first are ignored.
Types ¶
type Error ¶
type Error struct { // UserID is the name of the user attempting the operation. UserID eventdb.UserID // Op is the operation being performed, usually the name of the // method being invoked. Op Op // 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 // contains filtered or unexported fields }
Error is a domain error for eventdb. It contains fields used to populate parts of the error message. Some of the fields may be left unset.
type Kind ¶
type Kind int
Kind defines the kind of error this is, used for translating into HTTP status codes based on the type of error.
type Response ¶
type Response struct { Error string `json:"error,omitempty"` Details interface{} `json:"details,omitempty"` Status int `json:"status,omitempty"` }
Response is a JSON-serializable version of an Error. It can be used to transmit errors across the REST API.
func ResponseForError ¶
ResponseForError constructs an ErrorResponse based on an Error. Since this object is user-visible it's not a 1-1 mapping. Some errors will return detailed information about why the error happened in the Error and Details sections. Others wil just return an opaque error type.