1
2
3
4
5
6
7
8
9
10 package kerr
11
12 import (
13 "errors"
14 "fmt"
15 )
16
17
18 type Error struct {
19
20
21 Message string
22
23 Code int16
24
25 Retriable bool
26
27 Description string
28 }
29
30 func (e *Error) Error() string {
31 return fmt.Sprintf("%s: %s", e.Message, e.Description)
32 }
33
34
35
36
37
38 func ErrorForCode(code int16) error {
39 err, exists := code2err[code]
40 if !exists {
41 return UnknownServerError
42 }
43 return err
44 }
45
46
47
48
49
50
51
52
53
54
55
56
57
58 func TypedErrorForCode(code int16) *Error {
59 err, exists := code2err[code]
60 if !exists {
61 return UnknownServerError
62 }
63 if err == nil {
64 return nil
65 }
66 return err.(*Error)
67 }
68
69
70 func IsRetriable(err error) bool {
71 var kerr *Error
72 return errors.As(err, &kerr) && kerr.Retriable
73 }
74
75 var (
76 UnknownServerError = &Error{"UNKNOWN_SERVER_ERROR", -1, false, "The server experienced an unexpected error when processing the request."}
77 OffsetOutOfRange = &Error{"OFFSET_OUT_OF_RANGE", 1, false, "The requested offset is not within the range of offsets maintained by the server."}
78 CorruptMessage = &Error{"CORRUPT_MESSAGE", 2, true, "This message has failed its CRC checksum, exceeds the valid size, has a null key for a compacted topic, or is otherwise corrupt."}
79 UnknownTopicOrPartition = &Error{"UNKNOWN_TOPIC_OR_PARTITION", 3, true, "This server does not host this topic-partition."}
80 InvalidFetchSize = &Error{"INVALID_FETCH_SIZE", 4, false, "The requested fetch size is invalid."}
81 LeaderNotAvailable = &Error{"LEADER_NOT_AVAILABLE", 5, true, "There is no leader for this topic-partition as we are in the middle of a leadership election."}
82 NotLeaderForPartition = &Error{"NOT_LEADER_FOR_PARTITION", 6, true, "This server is not the leader for that topic-partition."}
83 RequestTimedOut = &Error{"REQUEST_TIMED_OUT", 7, true, "The request timed out."}
84 BrokerNotAvailable = &Error{"BROKER_NOT_AVAILABLE", 8, true, "The broker is not available."}
85 ReplicaNotAvailable = &Error{"REPLICA_NOT_AVAILABLE", 9, true, "The replica is not available for the requested topic-partition."}
86 MessageTooLarge = &Error{"MESSAGE_TOO_LARGE", 10, false, "The request included a message larger than the max message size the server will accept."}
87 StaleControllerEpoch = &Error{"STALE_CONTROLLER_EPOCH", 11, false, "The controller moved to another broker."}
88 OffsetMetadataTooLarge = &Error{"OFFSET_METADATA_TOO_LARGE", 12, false, "The metadata field of the offset request was too large."}
89 NetworkException = &Error{"NETWORK_EXCEPTION", 13, true, "The server disconnected before a response was received."}
90 CoordinatorLoadInProgress = &Error{"COORDINATOR_LOAD_IN_PROGRESS", 14, true, "The coordinator is loading and hence can't process requests."}
91 CoordinatorNotAvailable = &Error{"COORDINATOR_NOT_AVAILABLE", 15, true, "The coordinator is not available."}
92 NotCoordinator = &Error{"NOT_COORDINATOR", 16, true, "This is not the correct coordinator."}
93 InvalidTopicException = &Error{"INVALID_TOPIC_EXCEPTION", 17, false, "The request attempted to perform an operation on an invalid topic."}
94 RecordListTooLarge = &Error{"RECORD_LIST_TOO_LARGE", 18, false, "The request included message batch larger than the configured segment size on the server."}
95 NotEnoughReplicas = &Error{"NOT_ENOUGH_REPLICAS", 19, true, "Messages are rejected since there are fewer in-sync replicas than required."}
96 NotEnoughReplicasAfterAppend = &Error{"NOT_ENOUGH_REPLICAS_AFTER_APPEND", 20, true, "Messages are written to the log, but to fewer in-sync replicas than required."}
97 InvalidRequiredAcks = &Error{"INVALID_REQUIRED_ACKS", 21, false, "Produce request specified an invalid value for required acks."}
98 IllegalGeneration = &Error{"ILLEGAL_GENERATION", 22, false, "Specified group generation id is not valid."}
99 InconsistentGroupProtocol = &Error{"INCONSISTENT_GROUP_PROTOCOL", 23, false, "The group member's supported protocols are incompatible with those of existing members or first group member tried to join with empty protocol type or empty protocol list."}
100 InvalidGroupID = &Error{"INVALID_GROUP_ID", 24, false, "The configured groupID is invalid."}
101 UnknownMemberID = &Error{"UNKNOWN_MEMBER_ID", 25, false, "The coordinator is not aware of this member."}
102 InvalidSessionTimeout = &Error{"INVALID_SESSION_TIMEOUT", 26, false, "The session timeout is not within the range allowed by the broker (as configured by group.min.session.timeout.ms and group.max.session.timeout.ms)."}
103 RebalanceInProgress = &Error{"REBALANCE_IN_PROGRESS", 27, false, "The group is rebalancing, so a rejoin is needed."}
104 InvalidCommitOffsetSize = &Error{"INVALID_COMMIT_OFFSET_SIZE", 28, false, "The committing offset data size is not valid."}
105 TopicAuthorizationFailed = &Error{"TOPIC_AUTHORIZATION_FAILED", 29, false, "Not authorized to access topics: [Topic authorization failed.]"}
106 GroupAuthorizationFailed = &Error{"GROUP_AUTHORIZATION_FAILED", 30, false, "Not authorized to access group: Group authorization failed."}
107 ClusterAuthorizationFailed = &Error{"CLUSTER_AUTHORIZATION_FAILED", 31, false, "Cluster authorization failed."}
108 InvalidTimestamp = &Error{"INVALID_TIMESTAMP", 32, false, "The timestamp of the message is out of acceptable range."}
109 UnsupportedSaslMechanism = &Error{"UNSUPPORTED_SASL_MECHANISM", 33, false, "The broker does not support the requested SASL mechanism."}
110 IllegalSaslState = &Error{"ILLEGAL_SASL_STATE", 34, false, "Request is not valid given the current SASL state."}
111 UnsupportedVersion = &Error{"UNSUPPORTED_VERSION", 35, false, "The version of API is not supported."}
112 TopicAlreadyExists = &Error{"TOPIC_ALREADY_EXISTS", 36, false, "Topic with this name already exists."}
113 InvalidPartitions = &Error{"INVALID_PARTITIONS", 37, false, "Number of partitions is below 1."}
114 InvalidReplicationFactor = &Error{"INVALID_REPLICATION_FACTOR", 38, false, "Replication factor is below 1 or larger than the number of available brokers."}
115 InvalidReplicaAssignment = &Error{"INVALID_REPLICA_ASSIGNMENT", 39, false, "Replica assignment is invalid."}
116 InvalidConfig = &Error{"INVALID_CONFIG", 40, false, "Configuration is invalid."}
117 NotController = &Error{"NOT_CONTROLLER", 41, true, "This is not the correct controller for this cluster."}
118 InvalidRequest = &Error{"INVALID_REQUEST", 42, false, "This most likely occurs because of a request being malformed by the client library or the message was sent to an incompatible broker. See the broker logs for more details."}
119 UnsupportedForMessageFormat = &Error{"UNSUPPORTED_FOR_MESSAGE_FORMAT", 43, false, "The message format version on the broker does not support the request."}
120 PolicyViolation = &Error{"POLICY_VIOLATION", 44, false, "Request parameters do not satisfy the configured policy."}
121 OutOfOrderSequenceNumber = &Error{"OUT_OF_ORDER_SEQUENCE_NUMBER", 45, false, "The broker received an out of order sequence number."}
122 DuplicateSequenceNumber = &Error{"DUPLICATE_SEQUENCE_NUMBER", 46, false, "The broker received a duplicate sequence number."}
123 InvalidProducerEpoch = &Error{"INVALID_PRODUCER_EPOCH", 47, false, "Producer attempted an operation with an old epoch."}
124 InvalidTxnState = &Error{"INVALID_TXN_STATE", 48, false, "The producer attempted a transactional operation in an invalid state."}
125 InvalidProducerIDMapping = &Error{"INVALID_PRODUCER_ID_MAPPING", 49, false, "The producer attempted to use a producer id which is not currently assigned to its transactional id."}
126 InvalidTransactionTimeout = &Error{"INVALID_TRANSACTION_TIMEOUT", 50, false, "The transaction timeout is larger than the maximum value allowed by the broker (as configured by transaction.max.timeout.ms)."}
127 ConcurrentTransactions = &Error{"CONCURRENT_TRANSACTIONS", 51, false, "The producer attempted to update a transaction while another concurrent operation on the same transaction was ongoing."}
128 TransactionCoordinatorFenced = &Error{"TRANSACTION_COORDINATOR_FENCED", 52, false, "Indicates that the transaction coordinator sending a WriteTxnMarker is no longer the current coordinator for a given producer."}
129 TransactionalIDAuthorizationFailed = &Error{"TRANSACTIONAL_ID_AUTHORIZATION_FAILED", 53, false, "Transactional ID authorization failed."}
130 SecurityDisabled = &Error{"SECURITY_DISABLED", 54, false, "Security features are disabled."}
131 OperationNotAttempted = &Error{"OPERATION_NOT_ATTEMPTED", 55, false, "The broker did not attempt to execute this operation. This may happen for batched RPCs where some operations in the batch failed, causing the broker to respond without trying the rest."}
132 KafkaStorageError = &Error{"KAFKA_STORAGE_ERROR", 56, true, "Disk error when trying to access log file on the disk."}
133 LogDirNotFound = &Error{"LOG_DIR_NOT_FOUND", 57, false, "The user-specified log directory is not found in the broker config."}
134 SaslAuthenticationFailed = &Error{"SASL_AUTHENTICATION_FAILED", 58, false, "SASL Authentication failed."}
135 UnknownProducerID = &Error{"UNKNOWN_PRODUCER_ID", 59, false, "This exception is raised by the broker if it could not locate the producer metadata associated with the producerID in question. This could happen if, for instance, the producer's records were deleted because their retention time had elapsed. Once the last records of the producerID are removed, the producer's metadata is removed from the broker, and future appends by the producer will return this exception."}
136 ReassignmentInProgress = &Error{"REASSIGNMENT_IN_PROGRESS", 60, false, "A partition reassignment is in progress."}
137 DelegationTokenAuthDisabled = &Error{"DELEGATION_TOKEN_AUTH_DISABLED", 61, false, "Delegation Token feature is not enabled."}
138 DelegationTokenNotFound = &Error{"DELEGATION_TOKEN_NOT_FOUND", 62, false, "Delegation Token is not found on server."}
139 DelegationTokenOwnerMismatch = &Error{"DELEGATION_TOKEN_OWNER_MISMATCH", 63, false, "Specified Principal is not valid Owner/Renewer."}
140 DelegationTokenRequestNotAllowed = &Error{"DELEGATION_TOKEN_REQUEST_NOT_ALLOWED", 64, false, "Delegation Token requests are not allowed on PLAINTEXT/1-way SSL channels and on delegation token authenticated channels."}
141 DelegationTokenAuthorizationFailed = &Error{"DELEGATION_TOKEN_AUTHORIZATION_FAILED", 65, false, "Delegation Token authorization failed."}
142 DelegationTokenExpired = &Error{"DELEGATION_TOKEN_EXPIRED", 66, false, "Delegation Token is expired."}
143 InvalidPrincipalType = &Error{"INVALID_PRINCIPAL_TYPE", 67, false, "Supplied principalType is not supported."}
144 NonEmptyGroup = &Error{"NON_EMPTY_GROUP", 68, false, "The group is not empty."}
145 GroupIDNotFound = &Error{"GROUP_ID_NOT_FOUND", 69, false, "The group id does not exist."}
146 FetchSessionIDNotFound = &Error{"FETCH_SESSION_ID_NOT_FOUND", 70, true, "The fetch session ID was not found."}
147 InvalidFetchSessionEpoch = &Error{"INVALID_FETCH_SESSION_EPOCH", 71, true, "The fetch session epoch is invalid."}
148 ListenerNotFound = &Error{"LISTENER_NOT_FOUND", 72, true, "There is no listener on the leader broker that matches the listener on which metadata request was processed."}
149 TopicDeletionDisabled = &Error{"TOPIC_DELETION_DISABLED", 73, false, "Topic deletion is disabled."}
150 FencedLeaderEpoch = &Error{"FENCED_LEADER_EPOCH", 74, true, "The leader epoch in the request is older than the epoch on the broker"}
151 UnknownLeaderEpoch = &Error{"UNKNOWN_LEADER_EPOCH", 75, true, "The leader epoch in the request is newer than the epoch on the broker"}
152 UnsupportedCompressionType = &Error{"UNSUPPORTED_COMPRESSION_TYPE", 76, false, "The requesting client does not support the compression type of given partition."}
153 StaleBrokerEpoch = &Error{"STALE_BROKER_EPOCH", 77, false, "Broker epoch has changed"}
154 OffsetNotAvailable = &Error{"OFFSET_NOT_AVAILABLE", 78, true, "The leader high watermark has not caught up from a recent leader election so the offsets cannot be guaranteed to be monotonically increasing"}
155 MemberIDRequired = &Error{"MEMBER_ID_REQUIRED", 79, false, "The group member needs to have a valid member id before actually entering a consumer group"}
156 PreferredLeaderNotAvailable = &Error{"PREFERRED_LEADER_NOT_AVAILABLE", 80, true, "The preferred leader was not available"}
157 GroupMaxSizeReached = &Error{"GROUP_MAX_SIZE_REACHED", 81, false, "The consumer group has reached its max size"}
158 FencedInstanceID = &Error{"FENCED_INSTANCE_ID", 82, false, "The broker rejected this static consumer since another consumer with the same group.instance.id has registered with a different member.id."}
159 EligibleLeadersNotAvailable = &Error{"ELIGIBLE_LEADERS_NOT_AVAILABLE", 83, true, "Eligible topic partition leaders are not available"}
160 ElectionNotNeeded = &Error{"ELECTION_NOT_NEEDED", 84, true, "Leader election not needed for topic partition"}
161 NoReassignmentInProgress = &Error{"NO_REASSIGNMENT_IN_PROGRESS", 85, false, "No partition reassignment is in progress."}
162 GroupSubscribedToTopic = &Error{"GROUP_SUBSCRIBED_TO_TOPIC", 86, false, "Deleting offsets of a topic is forbidden while the consumer group is actively subscribed to it."}
163 InvalidRecord = &Error{"INVALID_RECORD", 87, false, "This record has failed the validation on broker and hence be rejected."}
164 UnstableOffsetCommit = &Error{"UNSTABLE_OFFSET_COMMIT", 88, true, "There are unstable offsets that need to be cleared."}
165 ThrottlingQuotaExceeded = &Error{"THROTTLING_QUOTA_EXCEEDED", 89, true, "The throttling quota has been exceeded."}
166 ProducerFenced = &Error{"PRODUCER_FENCED", 90, false, "There is a newer producer with the same transactionalId which fences the current one."}
167 ResourceNotFound = &Error{"RESOURCE_NOT_FOUND", 91, false, "A request illegally referred to a resource that does not exist."}
168 DuplicateResource = &Error{"DUPLICATE_RESOURCE", 92, false, "A request illegally referred to the same resource twice."}
169 UnacceptableCredential = &Error{"UNACCEPTABLE_CREDENTIAL", 93, false, "Requested credential would not meet criteria for acceptability."}
170 InconsistentVoterSet = &Error{"INCONSISTENT_VOTER_SET", 94, false, "Indicates that either the sender or recipient of a voter-only request is not one of the expected voters."}
171 InvalidUpdateVersion = &Error{"INVALID_UPDATE_VERSION", 95, false, "The given update version was invalid."}
172 FeatureUpdateFailed = &Error{"FEATURE_UPDATE_FAILED", 96, false, "Unable to update finalized features due to an unexpected server error."}
173 PrincipalDeserializationFailure = &Error{"PRINCIPAL_DESERIALIZATION_FAILURE", 97, false, "Request principal deserialization failed during forwarding. This indicates an internal error on the broker cluster security setup."}
174 SnapshotNotFound = &Error{"SNAPSHOT_NOT_FOUND", 98, false, "Requested snapshot was not found."}
175 PositionOutOfRange = &Error{"POSITION_OUT_OF_RANGE", 99, false, "Requested position is not greater than or equal to zero, and less than the size of the snapshot."}
176 UnknownTopicID = &Error{"UNKNOWN_TOPIC_ID", 100, true, "This server does not host this topic ID."}
177 DuplicateBrokerRegistration = &Error{"DUPLICATE_BROKER_REGISTRATION", 101, false, "This broker ID is already in use."}
178 BrokerIDNotRegistered = &Error{"BROKER_ID_NOT_REGISTERED", 102, false, "The given broker ID was not registered."}
179 InconsistentTopicID = &Error{"INCONSISTENT_TOPIC_ID", 103, true, "The log's topic ID did not match the topic ID in the request."}
180 InconsistentClusterID = &Error{"INCONSISTENT_CLUSTER_ID", 104, false, "The clusterId in the request does not match that found on the server."}
181 TransactionalIDNotFound = &Error{"TRANSACTIONAL_ID_NOT_FOUND", 105, false, "The transactionalId could not be found."}
182 FetchSessionTopicIDError = &Error{"FETCH_SESSION_TOPIC_ID_ERROR", 106, true, "The fetch session encountered inconsistent topic ID usage."}
183 IneligibleReplica = &Error{"INELIGIBLE_REPLICA", 107, false, "The new ISR contains at least one ineligible replica."}
184 NewLeaderElected = &Error{"NEW_LEADER_ELECTED", 108, false, "The AlterPartition request successfully updated the partition state but the leader has changed."}
185 OffsetMovedToTieredStorage = &Error{"OFFSET_MOVED_TO_TIERED_STORAGE", 109, false, "The requested offset is moved to tiered storage."}
186 )
187
188 var code2err = map[int16]error{
189 -1: UnknownServerError,
190 0: nil,
191 1: OffsetOutOfRange,
192 2: CorruptMessage,
193 3: UnknownTopicOrPartition,
194 4: InvalidFetchSize,
195 5: LeaderNotAvailable,
196 6: NotLeaderForPartition,
197 7: RequestTimedOut,
198 8: BrokerNotAvailable,
199 9: ReplicaNotAvailable,
200 10: MessageTooLarge,
201 11: StaleControllerEpoch,
202 12: OffsetMetadataTooLarge,
203 13: NetworkException,
204 14: CoordinatorLoadInProgress,
205 15: CoordinatorNotAvailable,
206 16: NotCoordinator,
207 17: InvalidTopicException,
208 18: RecordListTooLarge,
209 19: NotEnoughReplicas,
210 20: NotEnoughReplicasAfterAppend,
211 21: InvalidRequiredAcks,
212 22: IllegalGeneration,
213 23: InconsistentGroupProtocol,
214 24: InvalidGroupID,
215 25: UnknownMemberID,
216 26: InvalidSessionTimeout,
217 27: RebalanceInProgress,
218 28: InvalidCommitOffsetSize,
219 29: TopicAuthorizationFailed,
220 30: GroupAuthorizationFailed,
221 31: ClusterAuthorizationFailed,
222 32: InvalidTimestamp,
223 33: UnsupportedSaslMechanism,
224 34: IllegalSaslState,
225 35: UnsupportedVersion,
226 36: TopicAlreadyExists,
227 37: InvalidPartitions,
228 38: InvalidReplicationFactor,
229 39: InvalidReplicaAssignment,
230 40: InvalidConfig,
231 41: NotController,
232 42: InvalidRequest,
233 43: UnsupportedForMessageFormat,
234 44: PolicyViolation,
235 45: OutOfOrderSequenceNumber,
236 46: DuplicateSequenceNumber,
237 47: InvalidProducerEpoch,
238 48: InvalidTxnState,
239 49: InvalidProducerIDMapping,
240 50: InvalidTransactionTimeout,
241 51: ConcurrentTransactions,
242 52: TransactionCoordinatorFenced,
243 53: TransactionalIDAuthorizationFailed,
244 54: SecurityDisabled,
245 55: OperationNotAttempted,
246 56: KafkaStorageError,
247 57: LogDirNotFound,
248 58: SaslAuthenticationFailed,
249 59: UnknownProducerID,
250 60: ReassignmentInProgress,
251 61: DelegationTokenAuthDisabled,
252 62: DelegationTokenNotFound,
253 63: DelegationTokenOwnerMismatch,
254 64: DelegationTokenRequestNotAllowed,
255 65: DelegationTokenAuthorizationFailed,
256 66: DelegationTokenExpired,
257 67: InvalidPrincipalType,
258 68: NonEmptyGroup,
259 69: GroupIDNotFound,
260 70: FetchSessionIDNotFound,
261 71: InvalidFetchSessionEpoch,
262 72: ListenerNotFound,
263 73: TopicDeletionDisabled,
264 74: FencedLeaderEpoch,
265 75: UnknownLeaderEpoch,
266 76: UnsupportedCompressionType,
267 77: StaleBrokerEpoch,
268 78: OffsetNotAvailable,
269 79: MemberIDRequired,
270 80: PreferredLeaderNotAvailable,
271 81: GroupMaxSizeReached,
272 82: FencedInstanceID,
273 83: EligibleLeadersNotAvailable,
274 84: ElectionNotNeeded,
275 85: NoReassignmentInProgress,
276 86: GroupSubscribedToTopic,
277 87: InvalidRecord,
278 88: UnstableOffsetCommit,
279 89: ThrottlingQuotaExceeded,
280 90: ProducerFenced,
281 91: ResourceNotFound,
282 92: DuplicateResource,
283 93: UnacceptableCredential,
284 94: InconsistentVoterSet,
285 95: InvalidUpdateVersion,
286 96: FeatureUpdateFailed,
287 97: PrincipalDeserializationFailure,
288 98: SnapshotNotFound,
289 99: PositionOutOfRange,
290 100: UnknownTopicID,
291 101: DuplicateBrokerRegistration,
292 102: BrokerIDNotRegistered,
293 103: InconsistentTopicID,
294 104: InconsistentClusterID,
295 105: TransactionalIDNotFound,
296 106: FetchSessionTopicIDError,
297 107: IneligibleReplica,
298 108: NewLeaderElected,
299 109: OffsetMovedToTieredStorage,
300 }
301
View as plain text