errors.go 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package kafka
  2. // The various errors that can be returned by the Kafka server.
  3. // See https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol#AGuideToTheKafkaProtocol-ErrorCodes
  4. type KError int16
  5. const (
  6. NO_ERROR KError = 0
  7. UNKNOWN KError = -1
  8. OFFSET_OUT_OF_RANGE KError = 1
  9. INVALID_MESSAGE KError = 2
  10. UNKNOWN_TOPIC_OR_PARTITION KError = 3
  11. INVALID_MESSAGE_SIZE KError = 4
  12. LEADER_NOT_AVAILABLE KError = 5
  13. NOT_LEADER_FOR_PARTITION KError = 6
  14. REQUEST_TIMED_OUT KError = 7
  15. BROKER_NOT_AVAILABLE KError = 8
  16. REPLICA_NOT_AVAILABLE KError = 9
  17. MESSAGE_SIZE_TOO_LARGE KError = 10
  18. STALE_CONTROLLER_EPOCH_CODE KError = 11
  19. OFFSET_METADATA_TOO_LARGE KError = 12
  20. )
  21. func (err KError) Error() string {
  22. // Error messages stolen/adapted from
  23. // https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol
  24. switch err {
  25. case NO_ERROR:
  26. return "kafka server: Not an error, why are you printing me?"
  27. case UNKNOWN:
  28. return "kafka server: Unexpected (unknown?) server error."
  29. case OFFSET_OUT_OF_RANGE:
  30. return "kafka server: The requested offset is outside the range of offsets maintained by the server for the given topic/partition."
  31. case INVALID_MESSAGE:
  32. return "kafka server: Message contents does not match its CRC."
  33. case UNKNOWN_TOPIC_OR_PARTITION:
  34. return "kafka server: Request was for a topic or partition that does not exist on this broker."
  35. case INVALID_MESSAGE_SIZE:
  36. return "kafka server: The message has a negative size."
  37. case LEADER_NOT_AVAILABLE:
  38. return "kafka server: In the middle of a leadership election, there is currently no leader for this partition and hence it is unavailable for writes."
  39. case NOT_LEADER_FOR_PARTITION:
  40. return "kafka server: Tried to send a message to a replica that is not the leader for some partition. Your metadata is out of date."
  41. case REQUEST_TIMED_OUT:
  42. return "kafka server: Request exceeded the user-specified time limit in the request."
  43. case BROKER_NOT_AVAILABLE:
  44. return "kafka server: Broker not available. Not a client facing error, we should never receive this!!!"
  45. case REPLICA_NOT_AVAILABLE:
  46. return "kafka server: Replica not available. What is the difference between this and LeaderNotAvailable?"
  47. case MESSAGE_SIZE_TOO_LARGE:
  48. return "kafka server: Message was too large, server rejected it to avoid allocation error."
  49. case STALE_CONTROLLER_EPOCH_CODE:
  50. return "kafka server: Stale controller epoch code. ???"
  51. case OFFSET_METADATA_TOO_LARGE:
  52. return "kafka server: Specified a string larger than the configured maximum for offset metadata."
  53. default:
  54. return "Unknown error, how did this happen?"
  55. }
  56. }
  57. type OutOfBrokers struct {
  58. }
  59. func (err OutOfBrokers) Error() string {
  60. return "kafka: Client has run out of available brokers to talk to. Is your cluster reachable?"
  61. }
  62. // Returned when there was an error encoding a Kafka packet. This can happen, for example,
  63. // if you try to encode a string over 2^15 characters in length, since Kafka's encoding rules do
  64. // not permit that.
  65. type EncodingError string
  66. func (err EncodingError) Error() string {
  67. return "kafka: Could not encode packet. " + string(err)
  68. }
  69. // Returned when there was an error decoding the Kafka server's response. Usually means that you've
  70. // connected to the wrong address.
  71. type DecodingError string
  72. func (err DecodingError) Error() string {
  73. return "kafka: Could not decode packet. " + string(err)
  74. }