Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 45430d5235
Fetching contributors…

Cannot retrieve contributors at this time

60 lines (50 sloc) 1.251 kb
package redis
type ErrorFlag uint8
const (
ErrorRedis ErrorFlag = 1 << iota
ErrorConnection
ErrorLoading
ErrorAuth
ErrorParse
ErrorInvalid
ErrorTimeout
)
type Error struct {
Cmd Cmd // command that caused the error, if any
msg string
flags ErrorFlag
}
// newError creates a new Error.
func newError(msg string, flags ...ErrorFlag) *Error {
err := new(Error)
err.msg = msg
for _, f := range flags {
err.flags |= f
}
return err
}
// newErrorExt creates a new Error with flags of the given error and
// appends the error message from the given error to the end of the new one.
func newErrorExt(msg string, err *Error, flags ...ErrorFlag) *Error {
return newError(msg+": "+err.Error(), append(flags, err.flags)...)
}
// Error returns a string representation of the error.
func (e *Error) Error() string {
if e.Cmd != "" {
return string(e.Cmd) + ": " + e.msg
}
return e.msg
}
// Test returns true, if any of the given error flags is set in the error, otherwise false.
func (e *Error) Test(flags ...ErrorFlag) bool {
for _, f := range flags {
if e.flags&f > 0 {
return true
}
}
return false
}
// errmsg is a helper function for (panic) error messages.
func errmsg(msg string) string {
return "redis: " + msg
}
Jump to Line
Something went wrong with that request. Please try again.