1616# limitations under the License.
1717#
1818from confluent_kafka .cimpl import KafkaException , KafkaError
19-
2019from confluent_kafka .serialization import SerializationError
2120
2221
23- class ConsumeError (KafkaException ):
22+ class _KafkaClientError (KafkaException ):
2423 """
25- Wraps all errors encountered during the consumption of a message.
26-
27- Note:
28- In the event of a serialization error the original message contents
29- may be retrieved from the ``message`` attribute.
24+ Wraps all errors encountered by a Kafka Client
3025
3126 Args:
32- error_code (KafkaError): Error code indicating the type of error .
27+ kafka_error (KafkaError): KafkaError instance .
3328
3429 exception(Exception, optional): The original exception
3530
36- message (Message, optional): The Kafka Message returned from the broker.
37-
31+ kafka_message (Message, optional): The Kafka Message returned
32+ by the broker.
3833 """
39- def __init__ (self , error_code , exception = None , message = None ):
40- if exception is not None :
41- kafka_error = KafkaError (error_code , repr (exception ))
42- self .exception = exception
43- else :
44- kafka_error = KafkaError (error_code )
45- self .exception = None
4634
47- super (ConsumeError , self ).__init__ (kafka_error )
48- self .message = message
35+ def __init__ (self , kafka_error , exception = None , kafka_message = None ):
36+ super (_KafkaClientError , self ).__init__ (kafka_error )
37+ self .exception = exception
38+ self .kafka_message = kafka_message
4939
5040 @property
5141 def code (self ):
52- return self .code ()
42+ return self .args [ 0 ]. code ()
5343
5444 @property
5545 def name (self ):
56- return self .name ()
46+ return self .args [0 ].name ()
47+
48+
49+ class ConsumeError (_KafkaClientError ):
50+ """
51+ Wraps all errors encountered during the consumption of a message.
52+
53+ Note:
54+ In the event of a serialization error the original message
55+ contents may be retrieved from the ``kafka_message`` attribute.
56+
57+ Args:
58+ kafka_error (KafkaError): KafkaError instance.
59+
60+ exception(Exception, optional): The original exception
61+
62+ kafka_message (Message, optional): The Kafka Message
63+ returned by the broker.
64+
65+ """
66+
67+ def __init__ (self , kafka_error , exception = None , kafka_message = None ):
68+ super (ConsumeError , self ).__init__ (kafka_error , exception , kafka_message )
5769
5870
5971class KeyDeserializationError (ConsumeError , SerializationError ):
@@ -64,12 +76,15 @@ class KeyDeserializationError(ConsumeError, SerializationError):
6476 Args:
6577 exception(Exception, optional): The original exception
6678
67- message (Message, optional): The Kafka Message returned from the broker.
79+ kafka_message (Message, optional): The Kafka Message returned
80+ by the broker.
6881
6982 """
70- def __init__ (self , exception = None , message = None ):
83+
84+ def __init__ (self , exception = None , kafka_message = None ):
7185 super (KeyDeserializationError , self ).__init__ (
72- KafkaError ._KEY_DESERIALIZATION , exception = exception , message = message )
86+ KafkaError (KafkaError ._KEY_DESERIALIZATION , str (exception )),
87+ exception = exception , kafka_message = kafka_message )
7388
7489
7590class ValueDeserializationError (ConsumeError , SerializationError ):
@@ -80,41 +95,29 @@ class ValueDeserializationError(ConsumeError, SerializationError):
8095 Args:
8196 exception(Exception, optional): The original exception
8297
83- message (Message, optional): The Kafka Message returned from the broker.
98+ kafka_message (Message, optional): The Kafka Message returned
99+ by the broker.
84100
85101 """
86- def __init__ (self , exception = None , message = None ):
102+
103+ def __init__ (self , exception = None , kafka_message = None ):
87104 super (ValueDeserializationError , self ).__init__ (
88- KafkaError ._VALUE_DESERIALIZATION , exception = exception , message = message )
105+ KafkaError (KafkaError ._VALUE_DESERIALIZATION , str (exception )),
106+ exception = exception , kafka_message = kafka_message )
89107
90108
91- class ProduceError (KafkaException ):
109+ class ProduceError (_KafkaClientError ):
92110 """
93111 Wraps all errors encountered when Producing messages.
94112
95113 Args:
96- error_code (KafkaError): Error code indicating the type of error .
114+ kafka_error (KafkaError): KafkaError instance .
97115
98116 exception(Exception, optional): The original exception.
99-
100117 """
101- def __init__ (self , error_code , exception = None ):
102- if exception is not None :
103- kafka_error = KafkaError (error_code , repr (exception ))
104- self .exception = exception
105- else :
106- kafka_error = KafkaError (error_code )
107- self .exception = None
108118
109- super (ProduceError , self ).__init__ (kafka_error )
110-
111- @property
112- def code (self ):
113- return self .code ()
114-
115- @property
116- def name (self ):
117- return self .name ()
119+ def __init__ (self , kafka_error , exception = None ):
120+ super (ProduceError , self ).__init__ (kafka_error , exception , None )
118121
119122
120123class KeySerializationError (ProduceError , SerializationError ):
@@ -124,9 +127,11 @@ class KeySerializationError(ProduceError, SerializationError):
124127 Args:
125128 exception (Exception): The exception that occurred during serialization.
126129 """
130+
127131 def __init__ (self , exception = None ):
128132 super (KeySerializationError , self ).__init__ (
129- KafkaError ._KEY_SERIALIZATION , exception = exception )
133+ KafkaError (KafkaError ._KEY_SERIALIZATION , str (exception )),
134+ exception = exception )
130135
131136
132137class ValueSerializationError (ProduceError , SerializationError ):
@@ -136,6 +141,8 @@ class ValueSerializationError(ProduceError, SerializationError):
136141 Args:
137142 exception (Exception): The exception that occurred during serialization.
138143 """
144+
139145 def __init__ (self , exception = None ):
140146 super (ValueSerializationError , self ).__init__ (
141- KafkaError ._VALUE_SERIALIZATION , exception = exception )
147+ KafkaError (KafkaError ._VALUE_SERIALIZATION , str (exception )),
148+ exception = exception )
0 commit comments