packio
error_code.h
Go to the documentation of this file.
1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4 
5 #ifndef PACKIO_ERROR_CODE_H
6 #define PACKIO_ERROR_CODE_H
7 
10 
11 #include <type_traits>
12 
13 #include "internal/config.h"
14 
15 namespace packio {
16 
17 #if defined(PACKIO_STANDALONE_ASIO)
18 using error_code = std::error_code;
19 using system_error = std::system_error;
20 using error_category = std::error_category;
21 #else // defined(PACKIO_STANDALONE_ASIO)
22 using error_code = boost::system::error_code;
23 using system_error = boost::system::system_error;
24 using error_category = boost::system::error_category;
25 #endif // defined(PACKIO_STANDALONE_ASIO)
26 
28 enum class error {
29  success = 0,
32  cancelled,
33  call_error,
35 };
36 
37 struct packio_error_category : error_category {
38  const char* name() const noexcept override { return "packio"; }
39  std::string message(int ev) const override
40  {
41  switch (static_cast<error>(ev)) {
42  case error::success:
43  return "Success";
45  return "Error during call";
47  return "Unknown function";
48  case error::cancelled:
49  return "Cancelled";
50  case error::call_error:
51  return "Call error";
53  return "Bad result type";
54  default:
55  return "Unrecognized error";
56  }
57  }
58 };
59 
60 inline error_code make_error_code(error e)
61 {
62  static const packio_error_category category{};
63  return {static_cast<std::underlying_type<error>::type>(e), category};
64 }
65 
66 } // packio
67 
68 #if defined(PACKIO_STANDALONE_ASIO)
69 namespace std {
70 template <>
71 struct is_error_code_enum<::packio::error> : std::true_type {
72 };
73 } // std
74 #else // defined(PACKIO_STANDALONE_ASIO)
75 namespace boost::system {
76 template <>
77 struct is_error_code_enum<::packio::error> : std::true_type {
78 };
79 } // boost::system
80 #endif // defined(PACKIO_STANDALONE_ASIO)
81 
82 #endif // PACKIO_ERROR_CODE_H
packio::error::cancelled
@ cancelled
The operation has been cancelled.
packio::error::bad_result_type
@ bad_result_type
The result type is not as expected.
packio::error::call_error
@ call_error
An error happened during the call.
packio::error::success
@ success
Success.
packio::error::error_during_call
@ error_during_call
An error happened during the call, server-side error.
packio
Definition: as.h:16
packio::error::unknown_procedure
@ unknown_procedure
The procedure name is unknown, server-side error.
packio::error
error
The error codes enumeration.
Definition: error_code.h:28