gearman-go/client/error.go

43 lines
1.2 KiB
Go
Raw Normal View History

2013-08-29 16:51:23 +08:00
// Copyright 2011 - 2012 Xing Xing <mikespook@gmail.com>.
// All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package client
import (
2013-08-30 11:20:51 +08:00
"fmt"
2013-08-29 16:51:23 +08:00
"bytes"
"errors"
)
var (
ErrJobTimeOut = errors.New("Do a job time out")
ErrInvalidData = errors.New("Invalid data")
ErrWorkWarning = errors.New("Work warning")
ErrWorkFail = errors.New("Work fail")
ErrWorkException = errors.New("Work exeption")
ErrDataType = errors.New("Invalid data type")
ErrOutOfCap = errors.New("Out of the capability")
ErrNotConn = errors.New("Did not connect to job server")
ErrFuncNotFound = errors.New("The function was not found")
ErrConnection = errors.New("Connection error")
ErrNoActiveAgent = errors.New("No active agent")
ErrTimeOut = errors.New("Executing time out")
ErrUnknown = errors.New("Unknown error")
ErrConnClosed = errors.New("Connection closed")
)
func DisablePanic() { recover() }
// Extract the error message
2013-08-30 11:20:51 +08:00
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
}