Skip to content

Commit

Permalink
Merge pull request #104 from optiopay/add_error_types
Browse files Browse the repository at this point in the history
add support for new error codes
  • Loading branch information
hashmap committed Apr 27, 2018
2 parents 004b9ef + f68c292 commit 7a38838
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
78 changes: 78 additions & 0 deletions proto/errors.go
Expand Up @@ -38,6 +38,45 @@ var (
ErrGroupAuthorizationFailed = &KafkaError{30, "group authorization failed"}
ErrClusterAuthorizationFailed = &KafkaError{31, "cluster authorization failed"}
ErrInvalidTimeStamp = &KafkaError{32, "timestamp of the message is out of acceptable range"}
ErrUnsupportedSaslMechanism = &KafkaError{33, "The broker does not support the requested SASL mechanism."}
ErrIllegalSaslState = &KafkaError{34, "Request is not valid given the current SASL state."}
ErrUnsupportedVersion = &KafkaError{35, "The version of API is not supported."}
ErrTopicAlreadyExists = &KafkaError{36, "Topic with this name already exists."}
ErrInvalidPartitions = &KafkaError{37, "Number of partitions is invalid."}
ErrInvalidReplicationFactor = &KafkaError{38, "Replication-factor is invalid."}
ErrInvalidReplicaAssignment = &KafkaError{39, "Replica assignment is invalid."}
ErrInvalidConfig = &KafkaError{40, "Configuration is invalid."}
ErrNotController = &KafkaError{41, "This is not the correct controller for this cluster."}
ErrInvalidRequest = &KafkaError{42, "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."}
ErrUnsupportedForMessageFormat = &KafkaError{43, "The message format version on the broker does not support the request."}
ErrPolicyViolation = &KafkaError{44, "Request parameters do not satisfy the configured policy."}
ErrOutOfOrderSequenceNumber = &KafkaError{45, "The broker received an out of order sequence number"}
ErrDuplicateSequenceNumber = &KafkaError{46, "The broker received a duplicate sequence number"}
ErrInvalidProducerEpoch = &KafkaError{47, "Producer attempted an operation with an old epoch. Either there is a newer producer with the same transactionalId, or the producer's transaction has been expired by the broker."}
ErrInvalidTxnState = &KafkaError{48, "The producer attempted a transactional operation in an invalid state"}
ErrInvalidProducerIdMapping = &KafkaError{49, "The producer attempted to use a producer id which is not currently assigned to its transactional id"}
ErrInvalidTransactionTimeout = &KafkaError{50, "The transaction timeout is larger than the maximum value allowed by the broker (as configured by transaction.max.timeout.ms)."}
ErrConcurrentTransactions = &KafkaError{51, "The producer attempted to update a transaction while another concurrent operation on the same transaction was ongoing"}
ErrTransactionCoordinatorFenced = &KafkaError{52, "Indicates that the transaction coordinator sending a WriteTxnMarker is no longer the current coordinator for a given producer"}
ErrTransactionalIdAuthorizationFailed = &KafkaError{53, "Transactional Id authorization failed"}
ErrSecurityDisabled = &KafkaError{54, "Security features are disabled."}
ErrOperationNotAttempted = &KafkaError{55, "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."}
ErrKafkaStorageError = &KafkaError{56, "Disk error when trying to access log file on the disk."}
ErrLogDirNotFound = &KafkaError{57, "The user-specified log directory is not found in the broker config."}
ErrSaslAuthenticationFailed = &KafkaError{58, "SASL Authentication failed."}
ErrUnknownProducerId = &KafkaError{59, "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."}
ErrReassignmentInProgress = &KafkaError{60, "A partition reassignment is in progress"}
ErrDelegationTokenAuthDisabled = &KafkaError{61, "Delegation Token feature is not enabled."}
ErrDelegationTokenNotFound = &KafkaError{62, "Delegation Token is not found on server."}
ErrDelegationTokenOwnerMismatch = &KafkaError{63, "Specified Principal is not valid Owner/Renewer."}
ErrDelegationTokenRequestNotAllowed = &KafkaError{64, "Delegation Token requests are not allowed on PLAINTEXT/1-way SSL channels and on delegation token authenticated channels."}
ErrDelegationTokenAuthorizationFailed = &KafkaError{65, "Delegation Token authorization failed."}
ErrDelegationTokenExpired = &KafkaError{66, "Delegation Token is expired."}
ErrInvalidPrincipalType = &KafkaError{67, "Supplied principalType is not supported"}
ErrNonEmptyGroup = &KafkaError{68, "The group The group is not empty is not empty"}
ErrGroupIdNotFound = &KafkaError{69, "The group id The group id does not exist was not found"}
ErrFetchSessionIdNotFound = &KafkaError{70, "The fetch session ID was not found"}
ErrInvalidFetchSessionEpoch = &KafkaError{71, "The fetch session epoch is invalid"}

errnoToErr = map[int16]error{
-1: ErrUnknown,
Expand Down Expand Up @@ -73,6 +112,45 @@ var (
30: ErrGroupAuthorizationFailed,
31: ErrClusterAuthorizationFailed,
32: ErrInvalidCommitOffsetSize,
33: ErrUnsupportedSaslMechanism,
34: ErrIllegalSaslState,
35: ErrUnsupportedVersion,
36: ErrTopicAlreadyExists,
37: ErrInvalidPartitions,
38: ErrInvalidReplicationFactor,
39: ErrInvalidReplicaAssignment,
40: ErrInvalidConfig,
41: ErrNotController,
42: ErrInvalidRequest,
43: ErrUnsupportedForMessageFormat,
44: ErrPolicyViolation,
45: ErrOutOfOrderSequenceNumber,
46: ErrDuplicateSequenceNumber,
47: ErrInvalidProducerEpoch,
48: ErrInvalidTxnState,
49: ErrInvalidProducerIdMapping,
50: ErrInvalidTransactionTimeout,
51: ErrConcurrentTransactions,
52: ErrTransactionCoordinatorFenced,
53: ErrTransactionalIdAuthorizationFailed,
54: ErrSecurityDisabled,
55: ErrOperationNotAttempted,
56: ErrKafkaStorageError,
57: ErrLogDirNotFound,
58: ErrSaslAuthenticationFailed,
59: ErrUnknownProducerId,
60: ErrReassignmentInProgress,
61: ErrDelegationTokenAuthDisabled,
62: ErrDelegationTokenNotFound,
63: ErrDelegationTokenOwnerMismatch,
64: ErrDelegationTokenRequestNotAllowed,
65: ErrDelegationTokenAuthorizationFailed,
66: ErrDelegationTokenExpired,
67: ErrInvalidPrincipalType,
68: ErrNonEmptyGroup,
69: ErrGroupIdNotFound,
70: ErrFetchSessionIdNotFound,
71: ErrInvalidFetchSessionEpoch,
}
)

Expand Down
2 changes: 2 additions & 0 deletions proto/messages.go
Expand Up @@ -2480,6 +2480,7 @@ type TopicError struct {
Topic string
ErrorCode int16
ErrorMessage string // >= KafkaV1
Err error
}

type CreateTopicsResp struct {
Expand Down Expand Up @@ -2552,6 +2553,7 @@ func ReadVersionedCreateTopicsResp(r io.Reader, version int16) (*CreateTopicsRes
if resp.Version >= KafkaV1 {
te.ErrorMessage = dec.DecodeString()
}
te.Err = errFromNo(te.ErrorCode)
}

if dec.Err() != nil {
Expand Down
1 change: 1 addition & 0 deletions proto/messages_test.go
Expand Up @@ -1175,6 +1175,7 @@ func TestVersionedCreateTopicResponse(t *testing.T) {
TopicError{
ErrorCode: 1,
Topic: "mytopic",
Err: ErrOffsetOutOfRange,
},
},
}
Expand Down

0 comments on commit 7a38838

Please sign in to comment.