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.

пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 client
  6. import (
  7. "bytes"
  8. "errors"
  9. "fmt"
  10. )
  11. var (
  12. ErrJobTimeOut = errors.New("Do a job time out")
  13. ErrInvalidData = errors.New("Invalid data")
  14. ErrWorkWarning = errors.New("Work warning")
  15. ErrWorkFail = errors.New("Work fail")
  16. ErrWorkException = errors.New("Work exeption")
  17. ErrDataType = errors.New("Invalid data type")
  18. ErrOutOfCap = errors.New("Out of the capability")
  19. ErrNotConn = errors.New("Did not connect to job server")
  20. ErrFuncNotFound = errors.New("The function was not found")
  21. ErrConnection = errors.New("Connection error")
  22. ErrNoActiveAgent = errors.New("No active agent")
  23. ErrTimeOut = errors.New("Executing time out")
  24. ErrUnknown = errors.New("Unknown error")
  25. ErrConnClosed = errors.New("Connection closed")
  26. )
  27. // Extract the error message
  28. func GetError(data []byte) (err error) {
  29. rel := bytes.SplitN(data, []byte{'\x00'}, 2)
  30. if len(rel) != 2 {
  31. err = fmt.Errorf("Not a error data: %V", data)
  32. return
  33. }
  34. err = errors.New(fmt.Sprintf("%s: %s", rel[0], rel[1]))
  35. return
  36. }
  37. // Error handler
  38. type ErrorHandler func(error)