Skip to content

Commit 2f055e8

Browse files
committed
Remove connection error codes
Summary: related to T13767 Reviewers: ivica Reviewed By: ivica Subscribers: miljen, iljazovic Differential Revision: https://repo.mireo.local/D28117
1 parent 3d80f47 commit 2f055e8

File tree

2 files changed

+0
-263
lines changed

2 files changed

+0
-263
lines changed

include/async_mqtt5/error.hpp

Lines changed: 0 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -144,224 +144,14 @@ inline std::ostream& operator<<(std::ostream& os, const error& err) {
144144

145145
} // end namespace client
146146

147-
148-
namespace connection {
149-
150-
/**
151-
* \brief Defines error codes related to MQTT client connection.
152-
*
153-
* \details Encapsulates errors encountered during the process of establishing a connection.
154-
*/
155-
enum class error : int {
156-
/** Connection has been successfully established */
157-
success = 0,
158-
159-
/** An error occured during TLS handshake */
160-
tls_handshake_error = 1,
161-
162-
/** An error occured during WebSocket handshake */
163-
websocket_handshake_error = 2,
164-
165-
// CONNACK
166-
/** The Server does not wish to reveal the reason for the failure */
167-
unspecified_error = 128,
168-
169-
/** Data within the CONNECT packet could not be correctly parsed */
170-
malformed_packet = 129,
171-
172-
/** Data in the CONNECT packet does not conform to this specification */
173-
protocol_error = 130,
174-
175-
/** The CONNECT is valid but is not accepted by this Server */
176-
implementation_specific_error = 131,
177-
178-
/** The Server does not support the version of the MQTT protocol requested by the Client */
179-
unsupported_protocol_version = 132,
180-
181-
/** The Client Identifier is a valid string but is not allowed by the Server */
182-
client_identifier_not_valid = 133,
183-
184-
/** The Server does not accept the User Name or Password specified by the Client */
185-
bad_username_or_password = 134,
186-
187-
/** The Client is not authorized to connect */
188-
not_authorized = 135,
189-
190-
/** The MQTT Server is not available */
191-
server_unavailable = 136,
192-
193-
/** The Server is busy, try again later */
194-
server_busy = 137,
195-
196-
/** This Client has been banned by administrative action */
197-
banned = 138,
198-
199-
/** The authentication method is not supported or does not match the one currently in use. */
200-
bad_authentication_method = 140,
201-
202-
/** The Will Topic Name is not malformed, but is not accepted by this Server */
203-
topic_name_invalid = 144,
204-
205-
/** The CONNECT packet exceeded the maximum permissible size */
206-
packet_too_large = 149,
207-
208-
/** An implementation or administrative imposed limit has been exceeded */
209-
quota_exceeded = 151,
210-
211-
/** The Will Payload does not match the specified Payload Format Indicator */
212-
payload_format_invalid = 153,
213-
214-
/** The Server does not support retained messages, and Will Retain was set to 1 */
215-
retain_not_supported = 154,
216-
217-
/** The Server does not support the QoS set in Will QoS */
218-
qos_not_supported = 155,
219-
220-
/** The Client should temporarily use another server */
221-
use_another_server = 156,
222-
223-
/** The Client should permanently use another server */
224-
server_moved = 157,
225-
226-
/** The connection rate limit has been exceeded */
227-
connection_rate_exceeded = 159
228-
};
229-
230-
inline std::string connection_error_to_string(error err) {
231-
switch (err) {
232-
case error::success:
233-
return "Connection has been successfully established";
234-
case error::tls_handshake_error:
235-
return "Connection failed: An error occured during TLS handshake";
236-
case error::websocket_handshake_error:
237-
return "Connection failed: An error occured during WebSocket handshake";
238-
case error::unspecified_error:
239-
return "Connection failed: The Server does not wish to reveal "
240-
"the reason for the failure or none of the codes apply";
241-
case error::malformed_packet:
242-
return "Connection failed: Data within the CONNECT packet "
243-
"could not be correctly parsed";
244-
case error::protocol_error:
245-
return "Connection failed: Data in the CONNECT packet does"
246-
" not conform to this specification";
247-
case error::implementation_specific_error:
248-
return "Connection failed : The CONNECT is valid but "
249-
"is not accepted by this Server";
250-
case error::unsupported_protocol_version:
251-
return "Connection failed: The Server does not support the "
252-
"version of the MQTT protocol requested by the Client";
253-
case error::client_identifier_not_valid:
254-
return "Connection failed: The Client Identifier is a valid "
255-
"string but is not allowed by the Server";
256-
case error::bad_username_or_password:
257-
return "Connection failed: The Server does not accept the User Name "
258-
" or Password specified by the Client";
259-
case error::not_authorized:
260-
return "Connection failed: The Client is not authorized to connect";
261-
case error::server_unavailable:
262-
return "Connection failed: The MQTT Server is not available";
263-
case error::server_busy:
264-
return "Connection failed: The Server is busy, try again later";
265-
case error::banned:
266-
return "Connection failed: This Client has been banned "
267-
"by administrative action, contact the server administrator";
268-
case error::bad_authentication_method:
269-
return "Connection failed: The authentication method is not supported "
270-
"or does not match the authentication method currently in use";
271-
case error::topic_name_invalid:
272-
return "Connection failed: The Will Topic Name is not malformed, "
273-
"but is not accepted by this Server";
274-
case error::packet_too_large:
275-
return "Connection failed: The CONNECT packet exceeded the maximum "
276-
" permissible size";
277-
case error::quota_exceeded:
278-
return "Connection failed: An implementation or administrative "
279-
"imposed limit has been exceeded";
280-
case error::payload_format_invalid:
281-
return "Connection failed: The Will Payload does not match "
282-
"the specified Payload Format Indicator";
283-
case error::retain_not_supported:
284-
return "Connection failed: The Server does not support "
285-
"retained messages, and Will Retain was set to 1";
286-
case error::qos_not_supported:
287-
return "Connection failed: The Server does not support "
288-
"the QoS set in Will QoS";
289-
case error::use_another_server:
290-
return "Connection failed: The Client should temporarily "
291-
"use another server";
292-
case error::server_moved:
293-
return "Connection failed: The Client should permanently "
294-
"use another server";
295-
case error::connection_rate_exceeded:
296-
return "Connection failed: The connection rate limit "
297-
"has been exceeded";
298-
default:
299-
return "Unknown connection error";
300-
}
301-
}
302-
303-
struct connection_ec_category : public boost::system::error_category {
304-
const char* name() const noexcept override { return "mqtt_connection_error"; }
305-
std::string message(int ev) const noexcept override {
306-
return connection_error_to_string(static_cast<error>(ev));
307-
}
308-
};
309-
310-
/// Returns the error category associated with \ref connection::error.
311-
inline const connection_ec_category& get_error_code_category() {
312-
static connection_ec_category cat;
313-
return cat;
314-
}
315-
316-
/// Creates an \ref error_code from a \ref connection::error.
317-
inline boost::system::error_code make_error_code(error r) {
318-
return { static_cast<int>(r), get_error_code_category() };
319-
}
320-
321-
inline std::ostream& operator<<(std::ostream& os, const error& err) {
322-
os << get_error_code_category().name() << ":" << static_cast<int>(err);
323-
return os;
324-
}
325-
326-
} // end namespace connection
327-
328147
} // end namespace async_mqtt5
329148

330149
namespace boost::system {
331150

332151
template <>
333152
struct is_error_code_enum <async_mqtt5::client::error> : std::true_type {};
334153

335-
template <>
336-
struct is_error_code_enum <async_mqtt5::connection::error> : std::true_type {};
337-
338154
} // end namespace boost::system
339155

340-
namespace async_mqtt5 {
341-
342-
inline bool is_not_recoverable(boost::system::error_code ec) {
343-
using namespace connection;
344-
return ec == boost::asio::error::no_recovery ||
345-
ec == error::tls_handshake_error ||
346-
ec == error::websocket_handshake_error ||
347-
ec == error::malformed_packet ||
348-
ec == error::implementation_specific_error ||
349-
ec == error::unsupported_protocol_version ||
350-
ec == error::client_identifier_not_valid ||
351-
ec == error::bad_username_or_password ||
352-
ec == error::not_authorized ||
353-
ec == error::banned ||
354-
ec == error::bad_authentication_method ||
355-
ec == error::topic_name_invalid ||
356-
ec == error::packet_too_large ||
357-
ec == error::quota_exceeded ||
358-
ec == error::payload_format_invalid ||
359-
ec == error::retain_not_supported ||
360-
ec == error::qos_not_supported ||
361-
ec == error::use_another_server ||
362-
ec == error::server_moved;
363-
}
364-
365-
} // end namespace async_mqtt5
366156

367157
#endif // !ASYNC_MQTT5_ERROR_HPP

test/unit/error.cpp

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -50,59 +50,6 @@ BOOST_FIXTURE_TEST_CASE(client_ec_to_stream, client_error_codes) {
5050
}
5151
}
5252

53-
struct connection_error_codes {
54-
const connection::connection_ec_category& cat = connection::get_error_code_category();
55-
56-
const std::vector<connection::error> ecs = {
57-
connection::error::success,
58-
connection::error::tls_handshake_error,
59-
connection::error::websocket_handshake_error,
60-
connection::error::unspecified_error,
61-
connection::error::malformed_packet,
62-
connection::error::protocol_error,
63-
connection::error::implementation_specific_error,
64-
connection::error::unsupported_protocol_version,
65-
connection::error::client_identifier_not_valid,
66-
connection::error::bad_username_or_password,
67-
connection::error::not_authorized,
68-
connection::error::server_unavailable,
69-
connection::error::server_busy,
70-
connection::error::banned,
71-
connection::error::bad_authentication_method,
72-
connection::error::topic_name_invalid,
73-
connection::error::packet_too_large,
74-
connection::error::quota_exceeded,
75-
connection::error::payload_format_invalid,
76-
connection::error::retain_not_supported,
77-
connection::error::qos_not_supported,
78-
connection::error::use_another_server,
79-
connection::error::server_moved,
80-
connection::error::connection_rate_exceeded
81-
};
82-
};
83-
84-
BOOST_FIXTURE_TEST_CASE(connection_ec_to_string, connection_error_codes) {
85-
// Ensure that all branches of the switch/case are covered
86-
BOOST_TEST(cat.name());
87-
88-
constexpr auto default_output = "Unknown connection error";
89-
for (auto ec : ecs)
90-
BOOST_TEST(cat.message(static_cast<int>(ec)) != default_output);
91-
92-
// default branch
93-
BOOST_TEST(cat.message(3) == default_output);
94-
}
95-
96-
BOOST_FIXTURE_TEST_CASE(connection_ec_to_stream, connection_error_codes) {
97-
for (auto ec : ecs) {
98-
std::ostringstream stream;
99-
stream << ec;
100-
std::string expected = std::string(cat.name()) + ":" +
101-
std::to_string(static_cast<int>(ec));
102-
BOOST_TEST(stream.str() == expected);
103-
}
104-
}
105-
10653
using namespace reason_codes;
10754
struct client_reason_codes {
10855
const std::vector<reason_code> rcs = {

0 commit comments

Comments
 (0)