gearman-go/common/error.go
mikespook 7614c2678a make a new branch, refactoring codes
--HG--
branch : 0.1
rename : gearman/client/client.go => client/client.go
rename : gearman/client/client_test.go => client/client_test.go
rename : gearman/client/clientjob.go => client/job.go
rename : gearman/gearman.go => common/gearman.go
rename : gearman/worker/jobagent.go => worker/jobagent.go
rename : gearman/worker/worker.go => worker/worker.go
rename : gearman/worker/worker_test.go => worker/worker_test.go
rename : gearman/worker/workerjob.go => worker/workerjob.go
2012-05-22 20:05:39 +08:00

48 lines
1.3 KiB
Go

// 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 common
import (
"fmt"
"bytes"
"errors"
"syscall"
)
var (
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.")
)
// Extract the error message
func GetError(data []byte) (eno syscall.Errno, err error) {
rel := bytes.SplitN(data, []byte{'\x00'}, 2)
if len(rel) != 2 {
err = Errorf("Not a error data: %V", data)
return
}
l := len(rel[0])
eno = syscall.Errno(BytesToUint32([4]byte{rel[0][l-4], rel[0][l-3], rel[0][l-2], rel[0][l-1]}))
err = errors.New(string(rel[1]))
return
}
// Get a formated error
func Errorf(format string, msg ... interface{}) error {
return errors.New(fmt.Sprintf(format, msg ... ))
}
// An error handler
type ErrorHandler func(error)