You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

55 lines
1.7 KiB

  1. // Copyright 2011 - 2012 Xing Xing <mikespook@gmail.com>.
  2. // All rights reserved.
  3. // Use of this source code is governed by a MIT
  4. // license that can be found in the LICENSE file.
  5. package common
  6. import (
  7. "fmt"
  8. "bytes"
  9. "errors"
  10. "syscall"
  11. )
  12. var (
  13. ErrJobTimeOut = errors.New("Do a job time out")
  14. ErrInvalidData = errors.New("Invalid data")
  15. ErrWorkWarning = errors.New("Work warning")
  16. ErrWorkFail = errors.New("Work fail")
  17. ErrWorkException = errors.New("Work exeption")
  18. ErrDataType = errors.New("Invalid data type")
  19. ErrOutOfCap = errors.New("Out of the capability")
  20. ErrNotConn = errors.New("Did not connect to job server")
  21. ErrFuncNotFound = errors.New("The function was not found")
  22. ErrConnection = errors.New("Connection error")
  23. ErrNoActiveAgent = errors.New("No active agent")
  24. ErrTimeOut = errors.New("Executing time out")
  25. ErrUnknown = errors.New("Unknown error")
  26. ErrConnClosed = errors.New("Connection closed")
  27. )
  28. func DisablePanic() {recover()}
  29. // Extract the error message
  30. func GetError(data []byte) (eno syscall.Errno, err error) {
  31. rel := bytes.SplitN(data, []byte{'\x00'}, 2)
  32. if len(rel) != 2 {
  33. err = Errorf("Not a error data: %V", data)
  34. return
  35. }
  36. l := len(rel[0])
  37. eno = syscall.Errno(BytesToUint32([4]byte{rel[0][l-4], rel[0][l-3], rel[0][l-2], rel[0][l-1]}))
  38. err = errors.New(string(rel[1]))
  39. return
  40. }
  41. // Get a formated error
  42. func Errorf(format string, msg ... interface{}) error {
  43. return errors.New(fmt.Sprintf(format, msg ... ))
  44. }
  45. // An error handler
  46. type ErrorHandler func(error)