errors.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package kafka
  2. import "errors"
  3. // EncodingError is returned from a failure while encoding a Kafka packet. This can happen, for example,
  4. // if you try to encode a string over 2^15 characters in length, since Kafka's encoding rules do not permit that.
  5. var EncodingError = errors.New("kafka: Error while encoding packet.")
  6. // InsufficientData is returned when decoding and the packet is truncated. This can be expected
  7. // when requesting messages, since as an optimization the server is allowed to return a partial message at the end
  8. // of the message set.
  9. var InsufficientData = errors.New("kafka: Insufficient data to decode packet, more bytes expected.")
  10. // DecodingError is returned when there was an error (other than truncated data) decoding the Kafka broker's response.
  11. // This can be a bad CRC or length field, or any other invalid value.
  12. var DecodingError = errors.New("kafka: Error while decoding packet.")
  13. // KError is the type of error that can be returned directly by the Kafka broker.
  14. // See https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol#AGuideToTheKafkaProtocol-ErrorCodes
  15. type KError int16
  16. const (
  17. NO_ERROR KError = 0
  18. UNKNOWN KError = -1
  19. OFFSET_OUT_OF_RANGE KError = 1
  20. INVALID_MESSAGE KError = 2
  21. UNKNOWN_TOPIC_OR_PARTITION KError = 3
  22. INVALID_MESSAGE_SIZE KError = 4
  23. LEADER_NOT_AVAILABLE KError = 5
  24. NOT_LEADER_FOR_PARTITION KError = 6
  25. REQUEST_TIMED_OUT KError = 7
  26. BROKER_NOT_AVAILABLE KError = 8
  27. REPLICA_NOT_AVAILABLE KError = 9
  28. MESSAGE_SIZE_TOO_LARGE KError = 10
  29. STALE_CONTROLLER_EPOCH_CODE KError = 11
  30. OFFSET_METADATA_TOO_LARGE KError = 12
  31. )
  32. func (err KError) Error() string {
  33. // Error messages stolen/adapted from
  34. // https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol
  35. switch err {
  36. case NO_ERROR:
  37. return "kafka server: Not an error, why are you printing me?"
  38. case UNKNOWN:
  39. return "kafka server: Unexpected (unknown?) server error."
  40. case OFFSET_OUT_OF_RANGE:
  41. return "kafka server: The requested offset is outside the range of offsets maintained by the server for the given topic/partition."
  42. case INVALID_MESSAGE:
  43. return "kafka server: Message contents does not match its CRC."
  44. case UNKNOWN_TOPIC_OR_PARTITION:
  45. return "kafka server: Request was for a topic or partition that does not exist on this broker."
  46. case INVALID_MESSAGE_SIZE:
  47. return "kafka server: The message has a negative size."
  48. case LEADER_NOT_AVAILABLE:
  49. 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."
  50. case NOT_LEADER_FOR_PARTITION:
  51. 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."
  52. case REQUEST_TIMED_OUT:
  53. return "kafka server: Request exceeded the user-specified time limit in the request."
  54. case BROKER_NOT_AVAILABLE:
  55. return "kafka server: Broker not available. Not a client facing error, we should never receive this!!!"
  56. case REPLICA_NOT_AVAILABLE:
  57. return "kafka server: Replica not available. What is the difference between this and LeaderNotAvailable?"
  58. case MESSAGE_SIZE_TOO_LARGE:
  59. return "kafka server: Message was too large, server rejected it to avoid allocation error."
  60. case STALE_CONTROLLER_EPOCH_CODE:
  61. return "kafka server: Stale controller epoch code. ???"
  62. case OFFSET_METADATA_TOO_LARGE:
  63. return "kafka server: Specified a string larger than the configured maximum for offset metadata."
  64. default:
  65. return "Unknown error, how did this happen?"
  66. }
  67. }