userver: userver/kafka/exceptions.hpp Source File
Loading...
Searching...
No Matches
exceptions.hpp
1#pragma once
2
3#include <cstdint>
4#include <stdexcept>
5#include <string_view>
6
7USERVER_NAMESPACE_BEGIN
8
9namespace kafka {
10
11/// @brief Base exception thrown by Producer::Send and Producer::SendAsync
12/// on send or delivery errors.
13class SendException : public std::runtime_error {
14public:
15 using std::runtime_error::runtime_error;
16
17 /// @brief Returns whether it makes sense to retry failed send.
18 ///
19 /// @see
20 /// https://docs.confluent.io/platform/current/clients/librdkafka/html/md_INTRODUCTION.html#autotoc_md8
21 bool IsRetryable() const noexcept;
22
23protected:
24 SendException(const char* what, bool is_retryable);
25
26private:
27 const bool is_retryable_{false};
28};
29
30class DeliveryTimeoutException final : public SendException {
31 static constexpr const char* kWhat{
32 "Message is not delivered after `delivery_timeout` milliseconds. Hint: "
33 "Adjust `delivery_timeout` and `queue_buffering_*` options or manually "
34 "retry the send request."};
35
36public:
37 DeliveryTimeoutException();
38};
39
40class QueueFullException final : public SendException {
41 static constexpr const char* kWhat{
42 "The sending queue is full - send request cannot be scheduled. Hint: "
43 "Manually retry the error or increase `queue_buffering_max_messages` "
44 "and/or `queue_buffering_max_kbytes` config option."};
45
46public:
47 QueueFullException();
48};
49
50class MessageTooLargeException final : public SendException {
51 static constexpr const char* kWhat{
52 "Message size exceeds configured limit. Hint: increase "
53 "`message_max_bytes` config option."};
54
55public:
56 MessageTooLargeException();
57};
58
59class UnknownTopicException final : public SendException {
60 static constexpr const char* kWhat{"Given topic does not exist in cluster."};
61
62public:
63 UnknownTopicException();
64};
65
66class UnknownPartitionException final : public SendException {
67 static constexpr const char* kWhat = "Topic does not have given partition.";
68
69public:
70 UnknownPartitionException();
71};
72
73/// @brief Exception thrown when there is an error retrieving the offset range.
74class OffsetRangeException : public std::runtime_error {
75public:
76 using std::runtime_error::runtime_error;
77
78public:
79 OffsetRangeException(std::string_view what, std::string_view topic, std::uint32_t partition);
80};
81
82class OffsetRangeTimeoutException final : public OffsetRangeException {
83 static constexpr const char* kWhat = "Timeout while fetching offsets.";
84
85public:
86 OffsetRangeTimeoutException(std::string_view topic, std::uint32_t partition);
87};
88
89class TopicNotFoundException final : public std::runtime_error {
90public:
91 using std::runtime_error::runtime_error;
92};
93
94/// @brief Exception thrown when fetching metadata.
95class GetMetadataException : public std::runtime_error {
96public:
97 using std::runtime_error::runtime_error;
98
99public:
100 GetMetadataException(std::string_view what, std::string_view topic);
101};
102
103class GetMetadataTimeoutException final : public GetMetadataException {
104 static constexpr const char* kWhat = "Timeout while getting metadata.";
105
106public:
107 GetMetadataTimeoutException(std::string_view topic);
108};
109
110/// @brief Exception throw when parsing consumed messages headers.
111/// @see Message::GetHeaders
112class ParseHeadersException final : std::runtime_error {
113 static constexpr const char* kWhat = "Failed to parse headers";
114
115public:
116 ParseHeadersException(std::string_view error);
117};
118
119} // namespace kafka
120
121USERVER_NAMESPACE_END