gearman-go/client/error.go

31 lines
677 B
Go
Raw Normal View History

2013-08-29 16:51:23 +08:00
package client
import (
"bytes"
"errors"
2013-08-30 12:36:57 +08:00
"fmt"
2013-08-29 16:51:23 +08:00
)
var (
ErrWorkWarning = errors.New("Work warning")
ErrInvalidData = errors.New("Invalid data")
2013-08-29 16:51:23 +08:00
ErrWorkFail = errors.New("Work fail")
ErrWorkException = errors.New("Work exeption")
ErrDataType = errors.New("Invalid data type")
ErrLostConn = errors.New("Lost connection with Gearmand")
2013-08-29 16:51:23 +08:00
)
// Extract the error message
func getError(data []byte) (err error) {
2013-08-29 16:51:23 +08:00
rel := bytes.SplitN(data, []byte{'\x00'}, 2)
if len(rel) != 2 {
err = fmt.Errorf("Not a error data: %V", data)
return
}
2013-08-30 11:20:51 +08:00
err = errors.New(fmt.Sprintf("%s: %s", rel[0], rel[1]))
2013-08-29 16:51:23 +08:00
return
}
2013-08-30 12:36:57 +08:00
// Error handler
type ErrorHandler func(error)