File indexing completed on 2025-01-18 09:51:19
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_REDIS_ADAPTER_RESULT_HPP
0009 #define BOOST_REDIS_ADAPTER_RESULT_HPP
0010
0011 #include <boost/redis/resp3/type.hpp>
0012 #include <boost/redis/error.hpp>
0013 #include <boost/system/result.hpp>
0014 #include <string>
0015
0016 namespace boost::redis::adapter
0017 {
0018
0019
0020
0021
0022 struct error {
0023
0024 resp3::type data_type = resp3::type::invalid;
0025
0026
0027 std::string diagnostic;
0028 };
0029
0030
0031
0032
0033
0034
0035
0036 inline bool operator==(error const& a, error const& b)
0037 {
0038 return a.data_type == b.data_type && a.diagnostic == b.diagnostic;
0039 }
0040
0041
0042
0043
0044
0045
0046
0047 inline bool operator!=(error const& a, error const& b)
0048 {
0049 return !(a == b);
0050 }
0051
0052
0053
0054
0055 template <class Value>
0056 using result = system::result<Value, error>;
0057
0058 BOOST_NORETURN inline void
0059 throw_exception_from_error(error const & e, boost::source_location const &)
0060 {
0061 system::error_code ec;
0062 switch (e.data_type) {
0063 case resp3::type::simple_error:
0064 ec = redis::error::resp3_simple_error;
0065 break;
0066 case resp3::type::blob_error:
0067 ec = redis::error::resp3_blob_error;
0068 break;
0069 case resp3::type::null:
0070 ec = redis::error::resp3_null;
0071 break;
0072 default:
0073 BOOST_ASSERT_MSG(false, "Unexpected data type.");
0074 }
0075
0076 throw system::system_error(ec, e.diagnostic);
0077 }
0078
0079 }
0080
0081 #endif