16
16
# limitations under the License.
17
17
#
18
18
from confluent_kafka .cimpl import KafkaException , KafkaError
19
-
20
19
from confluent_kafka .serialization import SerializationError
21
20
22
21
23
- class ConsumeError (KafkaException ):
22
+ class _KafkaClientError (KafkaException ):
24
23
"""
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
30
25
31
26
Args:
32
- error_code (KafkaError): Error code indicating the type of error .
27
+ kafka_error (KafkaError): KafkaError instance .
33
28
34
29
exception(Exception, optional): The original exception
35
30
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.
38
33
"""
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
46
34
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
49
39
50
40
@property
51
41
def code (self ):
52
- return self .code ()
42
+ return self .args [ 0 ]. code ()
53
43
54
44
@property
55
45
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 )
57
69
58
70
59
71
class KeyDeserializationError (ConsumeError , SerializationError ):
@@ -64,12 +76,15 @@ class KeyDeserializationError(ConsumeError, SerializationError):
64
76
Args:
65
77
exception(Exception, optional): The original exception
66
78
67
- message (Message, optional): The Kafka Message returned from the broker.
79
+ kafka_message (Message, optional): The Kafka Message returned
80
+ by the broker.
68
81
69
82
"""
70
- def __init__ (self , exception = None , message = None ):
83
+
84
+ def __init__ (self , exception = None , kafka_message = None ):
71
85
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 )
73
88
74
89
75
90
class ValueDeserializationError (ConsumeError , SerializationError ):
@@ -80,41 +95,29 @@ class ValueDeserializationError(ConsumeError, SerializationError):
80
95
Args:
81
96
exception(Exception, optional): The original exception
82
97
83
- message (Message, optional): The Kafka Message returned from the broker.
98
+ kafka_message (Message, optional): The Kafka Message returned
99
+ by the broker.
84
100
85
101
"""
86
- def __init__ (self , exception = None , message = None ):
102
+
103
+ def __init__ (self , exception = None , kafka_message = None ):
87
104
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 )
89
107
90
108
91
- class ProduceError (KafkaException ):
109
+ class ProduceError (_KafkaClientError ):
92
110
"""
93
111
Wraps all errors encountered when Producing messages.
94
112
95
113
Args:
96
- error_code (KafkaError): Error code indicating the type of error .
114
+ kafka_error (KafkaError): KafkaError instance .
97
115
98
116
exception(Exception, optional): The original exception.
99
-
100
117
"""
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
108
118
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 )
118
121
119
122
120
123
class KeySerializationError (ProduceError , SerializationError ):
@@ -124,9 +127,11 @@ class KeySerializationError(ProduceError, SerializationError):
124
127
Args:
125
128
exception (Exception): The exception that occurred during serialization.
126
129
"""
130
+
127
131
def __init__ (self , exception = None ):
128
132
super (KeySerializationError , self ).__init__ (
129
- KafkaError ._KEY_SERIALIZATION , exception = exception )
133
+ KafkaError (KafkaError ._KEY_SERIALIZATION , str (exception )),
134
+ exception = exception )
130
135
131
136
132
137
class ValueSerializationError (ProduceError , SerializationError ):
@@ -136,6 +141,8 @@ class ValueSerializationError(ProduceError, SerializationError):
136
141
Args:
137
142
exception (Exception): The exception that occurred during serialization.
138
143
"""
144
+
139
145
def __init__ (self , exception = None ):
140
146
super (ValueSerializationError , self ).__init__ (
141
- KafkaError ._VALUE_SERIALIZATION , exception = exception )
147
+ KafkaError (KafkaError ._VALUE_SERIALIZATION , str (exception )),
148
+ exception = exception )
0 commit comments