userver: userver/kafka/exceptions.hpp Source File
Loading...
Searching...
No Matches
exceptions.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <cstdint>
7#include <exception>
8#include <map>
9#include <stdexcept>
10#include <string>
11#include <string_view>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace kafka {
16
19class SendException : public std::runtime_error {
20public:
21 using std::runtime_error::runtime_error;
22
27 bool IsRetryable() const noexcept;
28
29protected:
30 SendException(const char* what, bool is_retryable);
31
32private:
33 const bool is_retryable_{false};
34};
35
38class BulkSendException : public std::runtime_error {
39 static constexpr const char* kWhat{"Some messages was not delivered."};
40
41public:
42 using ExceptionMap = std::map<std::size_t, std::exception_ptr>;
43
44 explicit BulkSendException(ExceptionMap nested_exceptions);
45
48 const ExceptionMap& GetExceptions() const noexcept;
49
50private:
56 const ExceptionMap nested_exceptions_;
57};
58
59class 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
66public:
67 DeliveryTimeoutException();
68};
69
70class 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
77public:
78 QueueFullException();
79};
80
81class 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
87public:
88 MessageTooLargeException();
89};
90
91class UnknownTopicException final : public SendException {
92 static constexpr const char* kWhat{"Given topic does not exist in cluster."};
93
94public:
95 UnknownTopicException();
96};
97
98class UnknownPartitionException final : public SendException {
99 static constexpr const char* kWhat = "Topic does not have given partition.";
100
101public:
102 UnknownPartitionException();
103};
104
106class OffsetRangeException : public std::runtime_error {
107public:
108 using std::runtime_error::runtime_error;
109
110 OffsetRangeException(std::string_view what, std::string_view topic, std::uint32_t partition);
111};
112
113class OffsetRangeTimeoutException final : public OffsetRangeException {
114 static constexpr const char* kWhat = "Timeout while fetching offsets.";
115
116public:
117 OffsetRangeTimeoutException(std::string_view topic, std::uint32_t partition);
118};
119
120class TopicNotFoundException final : public std::runtime_error {
121public:
122 using std::runtime_error::runtime_error;
123};
124
126class GetMetadataException : public std::runtime_error {
127public:
128 using std::runtime_error::runtime_error;
129
130 GetMetadataException(std::string_view what, std::string_view topic);
131};
132
133class GetMetadataTimeoutException final : public GetMetadataException {
134 static constexpr const char* kWhat = "Timeout while getting metadata.";
135
136public:
137 GetMetadataTimeoutException(std::string_view topic);
138};
139
142class ParseHeadersException final : std::runtime_error {
143 static constexpr const char* kWhat = "Failed to parse headers";
144
145public:
146 ParseHeadersException(std::string_view error);
147};
148
153class SeekException final : public std::runtime_error {
154public:
155 using std::runtime_error::runtime_error;
156};
157
162class SeekInvalidArgumentException final : public std::invalid_argument {
163public:
164 using std::invalid_argument::invalid_argument;
165};
166
168class ConsumerRestartRequiredException final : public std::runtime_error {
169public:
170 explicit ConsumerRestartRequiredException(const std::string& message);
171};
172
173} // namespace kafka
174
175USERVER_NAMESPACE_END