userver
C++ Async Framework
Loading...
Searching...
No Matches
exceptions.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/kafka/exceptions.hpp
4
/// @brief Kafka client exceptions
5
6
#
include
<
cstdint
>
7
#
include
<
exception
>
8
#
include
<
map
>
9
#
include
<
stdexcept
>
10
#
include
<
string
>
11
#
include
<
string_view
>
12
13
USERVER_NAMESPACE_BEGIN
14
15
namespace
kafka {
16
17
/// @brief Base exception thrown by Producer::Send and Producer::SendAsync
18
/// on send or delivery errors.
19
class
SendException
:
public
std::runtime_error {
20
public
:
21
using
std::runtime_error::runtime_error;
22
23
/// @brief Returns whether it makes sense to retry failed send.
24
///
25
/// @see
26
/// https://docs.confluent.io/platform/current/clients/librdkafka/html/md_INTRODUCTION.html#autotoc_md8
27
bool
IsRetryable
()
const
noexcept
;
28
29
protected
:
30
SendException(
const
char
* what,
bool
is_retryable);
31
32
private
:
33
const
bool
is_retryable_{
false
};
34
};
35
36
/// @brief Base exception thrown by Producer::Send in bulk mode
37
/// in case of one or more send errors.
38
class
BulkSendException
:
public
std::runtime_error {
39
static
constexpr
const
char
* kWhat{
"Some messages was not delivered."
};
40
41
public
:
42
using
ExceptionMap = std::map<std::size_t, std::exception_ptr>;
43
44
explicit
BulkSendException(ExceptionMap nested_exceptions);
45
46
/// @return nested errors.
47
/// Nested exceptions are subclasses of SendException.
48
const
ExceptionMap&
GetExceptions
()
const
noexcept
;
49
50
private
:
51
/// @brief A mapping from the message's index in the bulk send operation
52
/// to the exception that occurred during its delivering.
53
/// @details Key: 0-based index of the element in the input batch.
54
/// Value: Pointer to the exception.
55
/// @note Contains only indices that resulted in an error.
56
const
ExceptionMap nested_exceptions_;
57
};
58
59
class
DeliveryTimeoutException
final
:
public
SendException
{
60
static
constexpr
const
char
* kWhat{
61
"Message is not delivered after `delivery_timeout` milliseconds. Hint: "
62
"Adjust `delivery_timeout` and `queue_buffering_*` options or manually "
63
"retry the send request."
64
};
65
66
public
:
67
DeliveryTimeoutException();
68
};
69
70
class
QueueFullException
final
:
public
SendException
{
71
static
constexpr
const
char
* kWhat{
72
"The sending queue is full - send request cannot be scheduled. Hint: "
73
"Manually retry the error or increase `queue_buffering_max_messages` "
74
"and/or `queue_buffering_max_kbytes` config option."
75
};
76
77
public
:
78
QueueFullException();
79
};
80
81
class
MessageTooLargeException
final
:
public
SendException
{
82
static
constexpr
const
char
* kWhat{
83
"Message size exceeds configured limit. Hint: increase "
84
"`message_max_bytes` config option."
85
};
86
87
public
:
88
MessageTooLargeException();
89
};
90
91
class
UnknownTopicException
final
:
public
SendException
{
92
static
constexpr
const
char
* kWhat{
"Given topic does not exist in cluster."
};
93
94
public
:
95
UnknownTopicException();
96
};
97
98
class
UnknownPartitionException
final
:
public
SendException
{
99
static
constexpr
const
char
* kWhat =
"Topic does not have given partition."
;
100
101
public
:
102
UnknownPartitionException();
103
};
104
105
/// @brief Exception thrown when there is an error retrieving the offset range.
106
class
OffsetRangeException
:
public
std::runtime_error {
107
public
:
108
using
std::runtime_error::runtime_error;
109
110
OffsetRangeException(std::string_view what, std::string_view topic, std::uint32_t partition);
111
};
112
113
class
OffsetRangeTimeoutException
final
:
public
OffsetRangeException
{
114
static
constexpr
const
char
* kWhat =
"Timeout while fetching offsets."
;
115
116
public
:
117
OffsetRangeTimeoutException(std::string_view topic, std::uint32_t partition);
118
};
119
120
class
TopicNotFoundException
final
:
public
std::runtime_error {
121
public
:
122
using
std::runtime_error::runtime_error;
123
};
124
125
/// @brief Exception thrown when fetching metadata.
126
class
GetMetadataException
:
public
std::runtime_error {
127
public
:
128
using
std::runtime_error::runtime_error;
129
130
GetMetadataException(std::string_view what, std::string_view topic);
131
};
132
133
class
GetMetadataTimeoutException
final
:
public
GetMetadataException
{
134
static
constexpr
const
char
* kWhat =
"Timeout while getting metadata."
;
135
136
public
:
137
GetMetadataTimeoutException(std::string_view topic);
138
};
139
140
/// @brief Exception thrown when parsing consumed messages headers.
141
/// @ref Message::GetHeaders
142
class
ParseHeadersException
final
: std::runtime_error {
143
static
constexpr
const
char
* kWhat =
"Failed to parse headers"
;
144
145
public
:
146
ParseHeadersException(std::string_view error);
147
};
148
149
/// @brief Exception thrown when Seek* process failed.
150
/// @ref ConsumerScope::Seek
151
/// @ref ConsumerScope::SeekToBeginning
152
/// @ref ConsumerScope::SeekToEnd
153
class
SeekException
final
:
public
std::runtime_error {
154
public
:
155
using
std::runtime_error::runtime_error;
156
};
157
158
/// @brief Exception thrown when Seek* arguments are invalid.
159
/// @ref ConsumerScope::Seek
160
/// @ref ConsumerScope::SeekToBeginning
161
/// @ref ConsumerScope::SeekToEnd
162
class
SeekInvalidArgumentException
final
:
public
std::invalid_argument {
163
public
:
164
using
std::invalid_argument::invalid_argument;
165
};
166
167
/// @brief Fatal librdkafka consumer error; polling stops and consumer is recreated.
168
/// @ref ConsumerImpl::ThrowIfRestartRequired
169
class
ConsumerRestartRequiredException
final
:
public
std::runtime_error {
170
public
:
171
explicit
ConsumerRestartRequiredException(
const
std::string& message);
172
};
173
174
}
// namespace kafka
175
176
USERVER_NAMESPACE_END
userver
kafka
exceptions.hpp
Generated on Tue Jun 30 2026 13:15:28 for userver by
Doxygen
1.13.2