error.ipp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright (c) 2018-2023 Marcelo Zimbres Silva ([email protected])
  2. *
  3. * Distributed under the Boost Software License, Version 1.0. (See
  4. * accompanying file LICENSE.txt)
  5. */
  6. #include <boost/redis/error.hpp>
  7. #include <boost/assert.hpp>
  8. namespace boost::redis {
  9. namespace detail {
  10. struct error_category_impl : system::error_category {
  11. virtual ~error_category_impl() = default;
  12. auto name() const noexcept -> char const* override
  13. {
  14. return "boost.redis";
  15. }
  16. auto message(int ev) const -> std::string override
  17. {
  18. switch(static_cast<error>(ev)) {
  19. case error::invalid_data_type: return "Invalid resp3 type.";
  20. case error::not_a_number: return "Can't convert string to number (maybe forgot to upgrade to RESP3?).";
  21. case error::exceeeds_max_nested_depth: return "Exceeds the maximum number of nested responses.";
  22. case error::unexpected_bool_value: return "Unexpected bool value.";
  23. case error::empty_field: return "Expected field value is empty.";
  24. case error::expects_resp3_simple_type: return "Expects a resp3 simple type.";
  25. case error::expects_resp3_aggregate: return "Expects resp3 aggregate.";
  26. case error::expects_resp3_map: return "Expects resp3 map.";
  27. case error::expects_resp3_set: return "Expects resp3 set.";
  28. case error::nested_aggregate_not_supported: return "Nested aggregate not_supported.";
  29. case error::resp3_simple_error: return "Got RESP3 simple-error.";
  30. case error::resp3_blob_error: return "Got RESP3 blob-error.";
  31. case error::incompatible_size: return "Aggregate container has incompatible size.";
  32. case error::not_a_double: return "Not a double.";
  33. case error::resp3_null: return "Got RESP3 null.";
  34. case error::not_connected: return "Not connected.";
  35. case error::resolve_timeout: return "Resolve timeout.";
  36. case error::connect_timeout: return "Connect timeout.";
  37. case error::pong_timeout: return "Pong timeout.";
  38. case error::ssl_handshake_timeout: return "SSL handshake timeout.";
  39. case error::sync_receive_push_failed: return "Can't receive server push synchronously without blocking.";
  40. case error::incompatible_node_depth: return "Incompatible node depth.";
  41. default: BOOST_ASSERT(false); return "Boost.Redis error.";
  42. }
  43. }
  44. };
  45. auto category() -> system::error_category const&
  46. {
  47. static error_category_impl instance;
  48. return instance;
  49. }
  50. } // detail
  51. auto make_error_code(error e) -> system::error_code
  52. {
  53. return system::error_code{static_cast<int>(e), detail::category()};
  54. }
  55. } // boost::redis::detail