pull/7315/merge
Lee *!* Clagett 2 months ago committed by GitHub
commit 5a241be9c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -31,8 +31,12 @@
namespace
{
struct category final : std::error_category
struct category final : monero::error_category
{
category() noexcept
: monero::error_category()
{}
virtual const char* name() const noexcept override final
{
return "common_category()";
@ -40,11 +44,13 @@ namespace
virtual std::string message(int value) const override final
{
switch (common_error(value))
switch (monero::error(value))
{
case common_error::kInvalidArgument:
return make_error_code(std::errc::invalid_argument).message();
case common_error::kInvalidErrorCode:
case monero::error::none:
return "No error (success)";
case monero::error::invalid_argument:
return make_error_code(monero::errc::invalid_argument).message();
case monero::error::invalid_error_code:
return "expect<T> was given an error value of zero";
default:
break;
@ -52,25 +58,38 @@ namespace
return "Unknown basic_category() value";
}
virtual std::error_condition default_error_condition(int value) const noexcept override final
virtual monero::error_condition default_error_condition(int value) const noexcept override final
{
// maps specific errors to generic `std::errc` cases.
switch (common_error(value))
switch (monero::error(value))
{
case common_error::kInvalidArgument:
case common_error::kInvalidErrorCode:
return std::errc::invalid_argument;
case monero::error::none:
return monero::errc::success;
case monero::error::invalid_argument:
case monero::error::invalid_error_code:
return monero::errc::invalid_argument;
default:
break;
}
return std::error_condition{value, *this};
return monero::error_condition{value, *this};
}
};
//! function in anonymous namespace allows compiler to optimize `error_category::failed` call
category const& category_instance() noexcept
{
static const category instance;
return instance;
}
}
std::error_category const& common_category() noexcept
namespace monero
{
static const category instance{};
return instance;
error_category const& default_category() noexcept
{
return category_instance();
}
error_code make_error_code(monero::error value) noexcept
{
return {int(value), category_instance()};
}
}

@ -27,27 +27,37 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <system_error>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <type_traits>
enum class common_error : int
#define MONERO_DECLARE_ERROR_ENUM(name) \
namespace boost { \
namespace system { \
template<> \
struct is_error_code_enum< name > \
: std::true_type \
{}; \
} \
}
namespace monero
{
// 0 is reserved for no error, as per expect<T>
kInvalidArgument = 1, //!< A function argument is invalid
kInvalidErrorCode //!< Default `std::error_code` given to `expect<T>`
};
namespace errc = boost::system::errc;
using error_category = boost::system::error_category;
using error_code = boost::system::error_code;
using error_condition = boost::system::error_condition;
using system_error = boost::system::system_error;
std::error_category const& common_category() noexcept;
enum class error : int
{
none = 0,
invalid_argument, //!< A function argument is invalid
invalid_error_code //!< Default `monero::error_code` given to `expect<T>`
};
inline std::error_code make_error_code(::common_error value) noexcept
{
return std::error_code{int(value), common_category()};
error_category const& default_category() noexcept;
error_code make_error_code(monero::error value) noexcept;
}
namespace std
{
template<>
struct is_error_code_enum<::common_error>
: true_type
{};
}
MONERO_DECLARE_ERROR_ENUM(monero::error)

@ -61,10 +61,10 @@ namespace detail
}
}
void expect::throw_(std::error_code ec, const char* msg, const char* file, unsigned line)
void expect::throw_(monero::error_code ec, const char* msg, const char* file, unsigned line)
{
if (msg || file)
throw std::system_error{ec, generate_error(msg, file, line)};
throw std::system_error{ec};
throw monero::system_error{ec, generate_error(msg, file, line)};
throw monero::system_error{ec};
}
} // detail

@ -36,12 +36,12 @@
#include "common/error.h"
//! If precondition fails, return `::error::kInvalidArgument` in current scope.
#define MONERO_PRECOND(...) \
do \
{ \
if (!( __VA_ARGS__ )) \
return {::common_error::kInvalidArgument}; \
//! If precondition fails, return `monero::error::invalid_argument` in current scope.
#define MONERO_PRECOND(...) \
do \
{ \
if (!( __VA_ARGS__ )) \
return {::monero::error::invalid_argument}; \
} while (0)
//! Check `expect<void>` and return errors in current scope.
@ -56,14 +56,14 @@
/*! Get `T` from `expect<T>` by `std::move` as-if by function call.
`expect<void>` returns nothing.
\throw std::system_error with `expect<T>::error()`, filename and line
\throw monero::system_error with `expect<T>::error()`, filename and line
number when `expect<T>::has_error() == true`.*/
#define MONERO_UNWRAP(...) \
::detail::expect::unwrap( __VA_ARGS__ , nullptr, __FILE__ , __LINE__ )
/* \throw std::system_error with `code` and `msg` as part of the details. The
/* \throw monero::system_error with `code` and `msg` as part of the details. The
filename and line number will automatically be injected into the explanation
string. `code` can be any enum convertible to `std::error_code`. */
string. `code` can be any enum convertible to `monero::error_code`. */
#define MONERO_THROW(code, msg) \
::detail::expect::throw_( code , msg , __FILE__ , __LINE__ )
@ -78,8 +78,8 @@ namespace detail
struct expect
{
//! \throw std::system_error with `ec`, optional `msg` and/or optional `file` + `line`.
static void throw_(std::error_code ec, const char* msg, const char* file, unsigned line);
//! \throw monero::system_error with `ec`, optional `msg` and/or optional `file` + `line`.
static void throw_(monero::error_code ec, const char* msg, const char* file, unsigned line);
//! If `result.has_error()` call `throw_`. Otherwise, \return `*result` by move.
template<typename T>
@ -98,9 +98,9 @@ namespace detail
/*!
`expect<T>` is a value or error implementation, similar to Rust std::result
or various C++ proposals (boost::expected, boost::outcome). This
implementation currently has a strict error type, `std::error_code`, and a
templated value type `T`. `expect<T>` is implicitly convertible from `T`
or `std::error_code`, and one `expect<T>` object type is implicitly
implementation currently has a strict error type, `monero::error_code`, and
a templated value type `T`. `expect<T>` is implicitly convertible from `T`
or `monero::error_code`, and one `expect<T>` object type is implicitly
convertible to another `expect<U>` object iff the destination value type
can be implicitly constructed from the source value type (i.e.
`struct U { ... U(T src) { ...} ... };`).
@ -109,14 +109,14 @@ namespace detail
comparison between different value types is allowed provided the two values
types have a `operator==` defined between them (i.e.
`assert(expect<int>{100} == expect<short>{100});`). Comparisons can also be
done against `std::error_code` objects or error code enums directly (i.e.
`assert(expect<int>{make_error_code(common_error::kInvalidArgument)} == error::kInvalidArgument)`).
Comparison of default constructed `std::error_code` will always fail.
"Generic" comparisons can be done with `std::error_condition` via the `matches`
method only (i.e.
`assert(expect<int>{make_error_code{common_error::kInvalidErrorCode}.matches(std::errc::invalid_argument))`),
`operator==` and `operator!=` will not work with `std::errc` or
`std::error_condition`. A comparison with `matches` is more expensive
done against `monero::error_code` objects or error code enums directly (i.e.
`assert(expect<int>{make_error_code(monero::error::invalid_argument)} == error::invalid_argument)`).
Comparison of default constructed `monero::error_code` will always fail.
"Generic" comparisons can be done with `monero::error_condition` via the
`matches` method only (i.e.
`assert(expect<int>{make_error_code{monero::error::invalid_error_code}.matches(monero::errc::invalid_argument))`),
`operator==` and `operator!=` will not work with `monero::errc` or
`monero::error_condition`. A comparison with `matches` is more expensive
because an equivalency between error categories is computed, but is
recommended when an error can be one of several categories (this is going
to be the case in nearly every situation when calling a function from
@ -142,7 +142,7 @@ class expect
}
// MEMBERS
std::error_code code_;
monero::error_code code_;
typename std::aligned_storage<sizeof(T), alignof(T)>::type storage_;
// MEMBERS
@ -162,7 +162,6 @@ class expect
void store(U&& value) noexcept(std::is_nothrow_constructible<T, U>())
{
new (std::addressof(storage_)) T{std::forward<U>(value)};
code_ = std::error_code{};
}
void maybe_throw() const
@ -173,24 +172,27 @@ class expect
public:
using value_type = T;
using error_type = std::error_code;
using error_type = monero::error_code;
expect() = delete;
/*! Store an error, `code`, in the `expect` object. If `code` creates a
`std::error_code` object whose `.value() == 0`, then `error()` will be set
to `::common_error::kInvalidErrorCode`. */
expect(std::error_code const& code) noexcept
`monero::error_code` object whose `.value() == 0`, then `error()` will be
set to `::monero::error::invalid_error_code`. */
expect(error_type const& code) noexcept
: code_(code), storage_()
{
if (!has_error())
code_ = ::common_error::kInvalidErrorCode;
code_ = ::monero::error::invalid_error_code;
}
//! Store a value, `val`, in the `expect` object.
expect(T val) noexcept(std::is_nothrow_move_constructible<T>())
: code_(), storage_()
: code_(monero::error::none), storage_()
{
/* `monero::error::none` is used instead of default constructor because
Boost error_code in 1.68+ is header based and drags many instructions
into other functions unless compiling in C++14+. */
store(std::move(val));
}
@ -274,16 +276,16 @@ public:
bool has_value() const noexcept { return !has_error(); }
//! \return Error - always safe to call. Empty when `!has_error()`.
std::error_code error() const noexcept { return code_; }
error_type error() const noexcept { return code_; }
//! \return Value if `has_value()` otherwise \throw `std::system_error{error()}`.
//! \return Value if `has_value()` otherwise \throw `monero::system_error{error()}`.
T& value() &
{
maybe_throw();
return get();
}
//! \return Value if `has_value()` otherwise \throw `std::system_error{error()}`.
//! \return Value if `has_value()` otherwise \throw `monero::system_error{error()}`.
T const& value() const &
{
maybe_throw();
@ -319,7 +321,7 @@ public:
}
//! \return False if `has_value()`, otherwise `error() == rhs`.
bool equal(std::error_code const& rhs) const noexcept
bool equal(error_type const& rhs) const noexcept
{
return has_error() && error() == rhs;
}
@ -328,14 +330,14 @@ public:
\note This function is `noexcept` when `U == T` is `noexcept`.
\return False if `has_error()`, otherwise `value() == rhs`.
*/
template<typename U, typename = detail::enable_if<!std::is_constructible<std::error_code, U>::value>>
template<typename U, typename = detail::enable_if<!std::is_constructible<error_type, U>::value>>
bool equal(U const& rhs) const noexcept(noexcept(*std::declval<expect<T>>() == rhs))
{
return has_value() && get() == rhs;
}
//! \return False if `has_value()`, otherwise `error() == rhs`.
bool matches(std::error_condition const& rhs) const noexcept
bool matches(monero::error_condition const& rhs) const noexcept
{
return has_error() && error() == rhs;
}
@ -344,22 +346,26 @@ public:
template<>
class expect<void>
{
std::error_code code_;
monero::error_code code_;
public:
using value_type = void;
using error_type = std::error_code;
using error_type = monero::error_code;
//! Create a successful object.
expect() noexcept
: code_()
: code_(monero::error::none)
{}
expect(std::error_code const& code) noexcept
/* `monero::error::none` is used instead of default constructor because
Boost error_code in 1.68+ is header based and drags many instructions
into other functions unless compiling in C++14+. */
expect(error_type const& code) noexcept
: code_(code)
{
if (!has_error())
code_ = ::common_error::kInvalidErrorCode;
code_ = ::monero::error::invalid_error_code;
}
expect(expect const&) = default;
@ -373,7 +379,7 @@ public:
bool has_error() const noexcept { return bool(code_); }
//! \return Error - alway
std::error_code error() const noexcept { return code_; }
error_type error() const noexcept { return code_; }
//! \return `error() == rhs.error()`.
bool equal(expect const& rhs) const noexcept
@ -382,13 +388,13 @@ public:
}
//! \return `has_error() && error() == rhs`.
bool equal(std::error_code const& rhs) const noexcept
bool equal(error_type const& rhs) const noexcept
{
return has_error() && error() == rhs;
}
//! \return False if `has_value()`, otherwise `error() == rhs`.
bool matches(std::error_condition const& rhs) const noexcept
bool matches(monero::error_condition const& rhs) const noexcept
{
return has_error() && error() == rhs;
}

@ -31,8 +31,12 @@
#include <string>
namespace {
struct category final : std::error_category
struct category final : monero::error_category
{
category() noexcept
: monero::error_category()
{}
virtual const char* name() const noexcept override final
{
return "lmdb::error_category()";
@ -46,7 +50,7 @@ namespace {
return "Unknown lmdb::error_category() value";
}
virtual std::error_condition default_error_condition(int value) const noexcept override final
virtual monero::error_condition default_error_condition(int value) const noexcept override final
{
switch (value)
{
@ -55,44 +59,53 @@ namespace {
break; // map to nothing generic
case MDB_PAGE_NOTFOUND:
case MDB_CORRUPTED:
return std::errc::bad_address;
return monero::errc::bad_address;
case MDB_PANIC:
case MDB_VERSION_MISMATCH:
case MDB_INVALID:
break; // map to nothing generic
case MDB_MAP_FULL:
return std::errc::no_buffer_space;
return monero::errc::no_buffer_space;
case MDB_DBS_FULL:
break; // map to nothing generic
case MDB_READERS_FULL:
case MDB_TLS_FULL:
return std::errc::no_lock_available;
return monero::errc::no_lock_available;
case MDB_TXN_FULL:
case MDB_CURSOR_FULL:
case MDB_PAGE_FULL:
case MDB_MAP_RESIZED:
break; // map to nothing generic
case MDB_INCOMPATIBLE:
return std::errc::invalid_argument;
return monero::errc::invalid_argument;
case MDB_BAD_RSLOT:
case MDB_BAD_TXN:
case MDB_BAD_VALSIZE:
case MDB_BAD_DBI:
return std::errc::invalid_argument;
return monero::errc::invalid_argument;
default:
return std::error_condition{value, std::generic_category()};
return monero::errc::errc_t(value);
}
return std::error_condition{value, *this};
return monero::error_condition{value, *this};
}
};
//! function in anonymous namespace allows compiler to optimize `error_category::failed` call
category const& category_instance() noexcept
{
static const category instance{};
return instance;
}
}
namespace lmdb
{
std::error_category const& error_category() noexcept
monero::error_category const& error_category() noexcept
{
static const category instance{};
return instance;
return category_instance();
}
monero::error_code make_error_code(const error value) noexcept
{
return {int(value), category_instance()};
}
}

@ -26,8 +26,7 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <system_error>
#include <type_traits>
#include "common/error.h"
//! Executes a LMDB command, and returns errors via `lmdb::error` enum.
#define MONERO_LMDB_CHECK(...) \
@ -47,18 +46,8 @@ namespace lmdb
// All other errors are the values reported by LMDB
};
std::error_category const& error_category() noexcept;
inline std::error_code make_error_code(error value) noexcept
{
return std::error_code{int(value), error_category()};
}
monero::error_category const& error_category() noexcept;
monero::error_code make_error_code(error value) noexcept;
}
namespace std
{
template<>
struct is_error_code_enum<::lmdb::error>
: true_type
{};
}
MONERO_DECLARE_ERROR_ENUM(lmdb::error)

@ -81,7 +81,7 @@ namespace lmdb
/*!
\param cur Iterate over keys starting at this cursor position.
\throw std::system_error if unexpected LMDB error. This can happen
\throw monero::system_error if unexpected LMDB error. This can happen
if `cur` is invalid.
*/
key_iterator(MDB_cursor* cur)
@ -149,7 +149,7 @@ namespace lmdb
object - the other fields in the struct `account` are never copied
from the database.
\throw std::system_error if LMDB has unexpected errors.
\throw monero::system_error if LMDB has unexpected errors.
\return C++ iterator starting at current cursor position.
*/
template<typename T = V, typename F = T, std::size_t offset = 0>
@ -167,7 +167,7 @@ namespace lmdb
will return a range of `decltype(account.id)` objects - the other
fields in the struct `account` are never copied from the database.
\throw std::system_error if LMDB has unexpected errors.
\throw monero::system_error if LMDB has unexpected errors.
\return An InputIterator range over values at cursor position.
*/
template<typename T = V, typename F = T, std::size_t offset = 0>
@ -228,7 +228,7 @@ namespace lmdb
}
/*!
\throw std::system_error if LMDB has unexpected errors.
\throw monero::system_error if LMDB has unexpected errors.
\return C++ iterator over database keys from current cursor
position that will reach `.is_end()` after the last key.
*/
@ -238,7 +238,7 @@ namespace lmdb
}
/*!
\throw std::system_error if LMDB has unexpected errors.
\throw monero::system_error if LMDB has unexpected errors.
\return Range from current cursor position until last key record.
Useful in for-each range loops or in templated code
*/

@ -41,7 +41,7 @@ namespace lmdb
namespace stream
{
/*
\throw std::system_error if unexpected LMDB error.
\throw monero::system_error if unexpected LMDB error.
\return 0 if `cur == nullptr`, otherwise count of values at current key.
*/
mdb_size_t count(MDB_cursor* cur);
@ -54,9 +54,9 @@ namespace lmdb
\param key expected key size or 0 to skip key size check.
\param value expected value size or 0 to skip value size check.
\throw std::system_error if `key != 0` and `key_.mv_size != key`.
\throw std::system_error if `value != 0` and `value_.mv_size != value`.
\throw std::system_error if `mdb_cursor_get` returns any error
\throw monero::system_error if `key != 0` and `key_.mv_size != key`.
\throw monero::system_error if `value != 0` and `value_.mv_size != value`.
\throw monero::system_error if `mdb_cursor_get` returns any error
other than `MDB_NOTFOUND`.
\return {key bytes, value bytes} or two empty spans if `MDB_NOTFOUND`.
@ -106,7 +106,7 @@ namespace lmdb
/*!
\param cur Iterate over values starting at this cursor position.
\throw std::system_error if unexpected LMDB error. This can happen
\throw monero::system_error if unexpected LMDB error. This can happen
if `cur` is invalid.
*/
value_iterator(MDB_cursor* cur)
@ -225,7 +225,7 @@ namespace lmdb
}
/*!
\throw std::system_error if LMDB has unexpected errors.
\throw monero::system_error if LMDB has unexpected errors.
\return Number of values at this key.
*/
std::size_t count() const
@ -243,7 +243,7 @@ namespace lmdb
object - the other fields in the struct `account` are never copied
from the database.
\throw std::system_error if LMDB has unexpected errors.
\throw monero::system_error if LMDB has unexpected errors.
\return C++ iterator starting at current cursor position.
*/
template<typename U = T, typename F = U, std::size_t offset = 0>
@ -261,7 +261,7 @@ namespace lmdb
will return a range of `decltype(account.id)` objects - the other
fields in the struct `account` are never copied from the database.
\throw std::system_error if LMDB has unexpected errors.
\throw monero::system_error if LMDB has unexpected errors.
\return An InputIterator range over values at cursor position.
*/
template<typename U = T, typename F = U, std::size_t offset = 0>

@ -107,7 +107,7 @@ namespace dandelionpp
{
// max value is used by `select_stem` as error case
if (stems == std::numeric_limits<std::size_t>::max())
MONERO_THROW(common_error::kInvalidArgument, "stems value cannot be max size_t");
MONERO_THROW(monero::error::invalid_argument, "stems value cannot be max size_t");
usage_count_.resize(stems);
if (stems < out_mapping_.size())

@ -33,18 +33,18 @@
namespace
{
struct net_category : std::error_category
struct net_category final : monero::error_category
{
net_category() noexcept
: std::error_category()
: monero::error_category()
{}
const char* name() const noexcept override
const char* name() const noexcept override final
{
return "net::error_category";
}
std::string message(int value) const override
std::string message(int value) const override final
{
switch (net::error(value))
{
@ -73,28 +73,38 @@ namespace
return "Unknown net::error";
}
std::error_condition default_error_condition(int value) const noexcept override
monero::error_condition default_error_condition(int value) const noexcept override final
{
switch (net::error(value))
{
case net::error::invalid_port:
case net::error::invalid_mask:
return std::errc::result_out_of_range;
return monero::errc::result_out_of_range;
case net::error::expected_tld:
case net::error::invalid_tor_address:
default:
break;
}
return std::error_condition{value, *this};
return monero::error_condition{value, *this};
}
};
//! function in anonymous namespace allows compiler to optimize `error_category::failed` call
net_category const& category_instance() noexcept
{
static const net_category category;
return category;
}
} // anonymous
namespace net
{
std::error_category const& error_category() noexcept
monero::error_category const& error_category() noexcept
{
return category_instance();
}
monero::error_code make_error_code(error value) noexcept
{
static const net_category instance{};
return instance;
return {int(value), category_instance()};
}
}

@ -29,8 +29,7 @@
#pragma once
#include <system_error>
#include <type_traits>
#include "common/error.h"
namespace net
{
@ -50,20 +49,11 @@ namespace net
};
//! \return `std::error_category` for `net` namespace.
std::error_category const& error_category() noexcept;
//! \return `monero::error_category` for `net` namespace.
monero::error_category const& error_category() noexcept;
//! \return `net::error` as a `std::error_code` value.
inline std::error_code make_error_code(error value) noexcept
{
return std::error_code{int(value), error_category()};
}
monero::error_code make_error_code(error value) noexcept;
}
namespace std
{
template<>
struct is_error_code_enum<::net::error>
: true_type
{};
}
MONERO_DECLARE_ERROR_ENUM(net::error)

@ -137,12 +137,22 @@ namespace socks
return boost::system::error_condition{value, *this};
}
};
//! function in anonymous namespace allows compiler to optimize `error_category::failed` call
const socks_category& category_instance() noexcept
{
static const socks_category instance;
return instance;
}
}
const boost::system::error_category& error_category() noexcept
{
static const socks_category instance{};
return instance;
return category_instance();
}
boost::system::error_code make_error_code(error value) noexcept
{
return {int(value), category_instance()};
}
struct client::completed

@ -76,18 +76,15 @@ namespace socks
};
/* boost::system::error_code is extended for easier compatibility with
boost::asio errors. If std::error_code is needed (with expect<T> for
instance), then upgrade to boost 1.65+ or use conversion code in
develop branch at boost/system/detail/std_interoperability.hpp */
boost::asio errors. If std::error_code is needed, then upgrade to boost
1.65+ or use conversion code in develop branch at
boost/system/detail/std_interoperability.hpp */
//! \return boost::system::error_category for net::socks namespace
const boost::system::error_category& error_category() noexcept;
//! \return net::socks::error as a boost::system::error_code.
inline boost::system::error_code make_error_code(error value) noexcept
{
return boost::system::error_code{int(value), socks::error_category()};
}
boost::system::error_code make_error_code(error value) noexcept;
//! Client support for socks connect and resolve commands.
class client

@ -64,7 +64,7 @@ namespace socks
{
std::uint16_t port = 0;
if (!epee::string_tools::get_xtype_from_string(port, remote_port))
throw std::system_error{net::error::invalid_port, "Remote port for socks proxy"};
throw monero::system_error{net::error::invalid_port, "Remote port for socks proxy"};
bool is_set = false;
std::uint32_t ip_address = 0;
@ -80,7 +80,7 @@ namespace socks
is_set = proxy->set_connect_command(remote_host, port);
if (!is_set || !net::socks::client::connect_and_send(proxy, proxy_address))
throw std::system_error{net::error::invalid_host, "Address for socks proxy"};
throw monero::system_error{net::error::invalid_host, "Address for socks proxy"};
timeout.async_wait(net::socks::client::async_close{std::move(proxy)});
}

@ -35,50 +35,67 @@
#include "byte_slice.h"
namespace net
{
namespace zmq
namespace
{
const std::error_category& error_category() noexcept
struct category final : monero::error_category
{
struct category final : std::error_category
category() noexcept
: monero::error_category()
{}
virtual const char* name() const noexcept override final
{
virtual const char* name() const noexcept override final
{
return "error::error_category()";
}
return "net::zmq::error_category()";
}
virtual std::string message(int value) const override final
{
char const* const msg = zmq_strerror(value);
if (msg)
return msg;
return "zmq_strerror failure";
}
virtual std::string message(int value) const override final
{
char const* const msg = zmq_strerror(value);
if (msg)
return msg;
return "zmq_strerror failure";
}
virtual std::error_condition default_error_condition(int value) const noexcept override final
virtual monero::error_condition default_error_condition(int value) const noexcept override final
{
// maps specific errors to generic `std::errc` cases.
switch (value)
{
// maps specific errors to generic `std::errc` cases.
switch (value)
{
case EFSM:
case ETERM:
break;
default:
/* zmq is using cerrno errors. C++ spec indicates that
`std::errc` values must be identical to the cerrno value.
So just map every zmq specific error to the generic errc
equivalent. zmq extensions must be in the switch or they
map to a non-existent errc enum value. */
return std::errc(value);
}
return std::error_condition{value, *this};
case EFSM:
case ETERM:
break;
default:
/* zmq is using cerrno errors. C++ spec indicates that
`std::errc` values must be identical to the cerrno value. So
just map every zmq specific error to the generic errc
equivalent. zmq extensions must be in the switch or they map
to a non-existent errc enum value. */
return monero::errc::errc_t(value);
}
};
return monero::error_condition{value, *this};
}
};
//! function in anonymous namespace allows compiler to optimize `error_category::failed` call
const category& category_instance() noexcept
{
static const category instance{};
return instance;
}
}
namespace net
{
namespace zmq
{
const monero::error_category& error_category() noexcept
{
return category_instance();
}
monero::error_code make_error_code(int code) noexcept
{
return {code, category_instance()};
}
void terminate::call(void* ptr) noexcept
{

@ -65,16 +65,13 @@ namespace net
namespace zmq
{
//! \return Category for ZMQ errors.
const std::error_category& error_category() noexcept;
const monero::error_category& error_category() noexcept;
//! \return `code` (usally from zmq_errno()`) using `net::zmq::error_category()`.
inline std::error_code make_error_code(int code) noexcept
{
return std::error_code{code, error_category()};
}
monero::error_code make_error_code(int code) noexcept;
//! \return Error from `zmq_errno()` using `net::zmq::error_category()`.
inline std::error_code get_error_code() noexcept
inline monero::error_code get_error_code() noexcept
{
return make_error_code(zmq_errno());
}

@ -177,7 +177,7 @@ void ZmqServer::serve()
}
}
}
catch (const std::system_error& e)
catch (const boost::system::system_error& e)
{
if (e.code() != net::zmq::make_error_code(ETERM))
MERROR("ZMQ RPC Server Error: " << e.what());

@ -119,15 +119,15 @@ namespace
template<typename T>
void conversion_bench()
{
EXPECT_TRUE((std::is_convertible<std::error_code, expect<T>>()));
EXPECT_TRUE((std::is_convertible<std::error_code&&, expect<T>>()));
EXPECT_TRUE((std::is_convertible<std::error_code&, expect<T>>()));
EXPECT_TRUE((std::is_convertible<std::error_code const&, expect<T>>()));
EXPECT_TRUE((std::is_constructible<expect<T>, std::error_code>()));
EXPECT_TRUE((std::is_constructible<expect<T>, std::error_code&&>()));
EXPECT_TRUE((std::is_constructible<expect<T>, std::error_code&>()));
EXPECT_TRUE((std::is_constructible<expect<T>, std::error_code const&>()));
EXPECT_TRUE((std::is_convertible<monero::error_code, expect<T>>()));
EXPECT_TRUE((std::is_convertible<monero::error_code&&, expect<T>>()));
EXPECT_TRUE((std::is_convertible<monero::error_code&, expect<T>>()));
EXPECT_TRUE((std::is_convertible<monero::error_code const&, expect<T>>()));
EXPECT_TRUE((std::is_constructible<expect<T>, monero::error_code>()));
EXPECT_TRUE((std::is_constructible<expect<T>, monero::error_code&&>()));
EXPECT_TRUE((std::is_constructible<expect<T>, monero::error_code&>()));
EXPECT_TRUE((std::is_constructible<expect<T>, monero::error_code const&>()));
}
}
@ -237,10 +237,10 @@ TEST(Expect, NoExcept)
EXPECT_TRUE(noexcept(std::declval<expect<int>>() != 0));
EXPECT_TRUE(noexcept(0 != std::declval<expect<int>>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, std::error_code>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, std::error_code&&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, std::error_code&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, std::error_code const&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, monero::error_code>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, monero::error_code&&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, monero::error_code&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, monero::error_code const&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, throw_construct>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, throw_construct&&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_construct>, throw_construct&>()));
@ -255,10 +255,10 @@ TEST(Expect, NoExcept)
EXPECT_TRUE(std::is_nothrow_move_assignable<expect<throw_construct>>());
EXPECT_TRUE(std::is_nothrow_destructible<expect<throw_construct>>());
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, std::error_code>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, std::error_code&&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, std::error_code&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, std::error_code const&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, monero::error_code>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, monero::error_code&&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, monero::error_code&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, monero::error_code const&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, throw_copies>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_copies>, throw_copies&&>()));
EXPECT_TRUE(!(std::is_nothrow_constructible<expect<throw_copies>, throw_copies&>()));
@ -285,10 +285,10 @@ TEST(Expect, NoExcept)
EXPECT_TRUE(noexcept(std::declval<expect<throw_copies>>() != std::declval<throw_moves>()));
EXPECT_TRUE(noexcept(std::declval<throw_moves>() != std::declval<expect<throw_copies>>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, std::error_code>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, std::error_code&&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, std::error_code&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, std::error_code const&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, monero::error_code>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, monero::error_code&&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, monero::error_code&>()));
EXPECT_TRUE((std::is_nothrow_constructible<expect<throw_moves>, monero::error_code const&>()));
EXPECT_TRUE(!(std::is_nothrow_constructible<expect<throw_moves>, throw_moves>()));
EXPECT_TRUE(!(std::is_nothrow_constructible<expect<throw_moves>, throw_moves&&>()));
EXPECT_TRUE(!(std::is_nothrow_constructible<expect<throw_moves>, throw_moves&>()));
@ -340,20 +340,20 @@ TEST(Expect, Assignment)
EXPECT_TRUE(val2.value() == "foobar");
EXPECT_TRUE(*val2 == "foobar");
EXPECT_TRUE(boost::equals(val2->c_str(), "foobar"));
EXPECT_EQ(val1.error(), std::error_code{});
EXPECT_EQ(val2.error(), std::error_code{});
EXPECT_TRUE(!val1.equal(std::error_code{}));
EXPECT_TRUE(!val2.equal(std::error_code{}));
EXPECT_TRUE(!(val1 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val1));
EXPECT_TRUE(!(val2 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val2));
EXPECT_TRUE(val1 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val1);
EXPECT_TRUE(val2 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val2);
EXPECT_TRUE(!val1.matches(std::error_condition{}));
EXPECT_TRUE(!val2.matches(std::error_condition{}));
EXPECT_EQ(val1.error(), monero::error::none);
EXPECT_EQ(val2.error(), monero::error::none);
EXPECT_TRUE(!val1.equal(monero::error::none));
EXPECT_TRUE(!val2.equal(monero::error::none));
EXPECT_TRUE(!(val1 == monero::error::none));
EXPECT_TRUE(!(monero::error::none == val1));
EXPECT_TRUE(!(val2 == monero::error::none));
EXPECT_TRUE(!(monero::error::none == val2));
EXPECT_TRUE(val1 != monero::error::none);
EXPECT_TRUE(monero::error::none != val1);
EXPECT_TRUE(val2 != monero::error::none);
EXPECT_TRUE(monero::error::none != val2);
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
val1 = std::move(val2);
@ -369,20 +369,20 @@ TEST(Expect, Assignment)
EXPECT_EQ(val2.value(), std::string{});
EXPECT_TRUE(*val2 == std::string{});
EXPECT_TRUE(boost::equals(val2->c_str(), ""));
EXPECT_EQ(val1.error(), std::error_code{});
EXPECT_EQ(val2.error(), std::error_code{});
EXPECT_TRUE(!val1.equal(std::error_code{}));
EXPECT_TRUE(!val2.equal(std::error_code{}));
EXPECT_TRUE(!(val1 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val1));
EXPECT_TRUE(!(val2 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val2));
EXPECT_TRUE(val1 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val1);
EXPECT_TRUE(val2 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val2);
EXPECT_TRUE(!val1.matches(std::error_condition{}));
EXPECT_TRUE(!val2.matches(std::error_condition{}));
EXPECT_EQ(val1.error(), monero::error::none);
EXPECT_EQ(val2.error(), monero::error::none);
EXPECT_TRUE(!val1.equal(monero::error::none));
EXPECT_TRUE(!val2.equal(monero::error::none));
EXPECT_TRUE(!(val1 == monero::error::none));
EXPECT_TRUE(!(monero::error::none == val1));
EXPECT_TRUE(!(val2 == monero::error::none));
EXPECT_TRUE(!(monero::error::none == val2));
EXPECT_TRUE(val1 != monero::error::none);
EXPECT_TRUE(monero::error::none != val1);
EXPECT_TRUE(val2 != monero::error::none);
EXPECT_TRUE(monero::error::none != val2);
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
val2 = val1;
@ -398,22 +398,22 @@ TEST(Expect, Assignment)
EXPECT_EQ(val2.value(), "foobar");
EXPECT_TRUE(*val2 == "foobar");
EXPECT_TRUE(boost::equals(val2->c_str(), "foobar"));
EXPECT_EQ(val1.error(), std::error_code{});
EXPECT_EQ(val2.error(), std::error_code{});
EXPECT_TRUE(!val1.equal(std::error_code{}));
EXPECT_TRUE(!val2.equal(std::error_code{}));
EXPECT_TRUE(!(val1 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val1));
EXPECT_TRUE(!(val2 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val2));
EXPECT_TRUE(val1 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val1);
EXPECT_TRUE(val2 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val2);
EXPECT_TRUE(!val1.matches(std::error_condition{}));
EXPECT_TRUE(!val2.matches(std::error_condition{}));
val1 = make_error_code(common_error::kInvalidArgument);
EXPECT_EQ(val1.error(), monero::error::none);
EXPECT_EQ(val2.error(), monero::error::none);
EXPECT_TRUE(!val1.equal(monero::error::none));
EXPECT_TRUE(!val2.equal(monero::error::none));
EXPECT_TRUE(!(val1 == monero::error::none));
EXPECT_TRUE(!(monero::error::none == val1));
EXPECT_TRUE(!(val2 == monero::error::none));
EXPECT_TRUE(!(monero::error::none == val2));
EXPECT_TRUE(val1 != monero::error::none);
EXPECT_TRUE(monero::error::none != val1);
EXPECT_TRUE(val2 != monero::error::none);
EXPECT_TRUE(monero::error::none != val2);
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
val1 = make_error_code(monero::error::invalid_argument);
ASSERT_TRUE(val1.has_error());
ASSERT_TRUE(val2.has_value());
@ -421,27 +421,27 @@ TEST(Expect, Assignment)
EXPECT_TRUE(bool(val2));
EXPECT_TRUE(!val1.has_value());
EXPECT_TRUE(!val2.has_error());
EXPECT_EQ(val1.error(), common_error::kInvalidArgument);
EXPECT_TRUE(val1 == common_error::kInvalidArgument);
EXPECT_TRUE(common_error::kInvalidArgument == val1);
EXPECT_EQ(val1.error(), monero::error::invalid_argument);
EXPECT_TRUE(val1 == monero::error::invalid_argument);
EXPECT_TRUE(monero::error::invalid_argument == val1);
EXPECT_STREQ(val2.value().c_str(), "foobar");
EXPECT_TRUE(*val2 == "foobar");
EXPECT_TRUE(boost::equals(val2->c_str(), "foobar"));
EXPECT_NE(val1.error(), std::error_code{});
EXPECT_EQ(val2.error(), std::error_code{});
EXPECT_TRUE(val1.equal(common_error::kInvalidArgument));
EXPECT_TRUE(!val2.equal(std::error_code{}));
EXPECT_TRUE(!(val1 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val1));
EXPECT_TRUE(!(val2 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val2));
EXPECT_TRUE(val1 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val1);
EXPECT_TRUE(val2 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val2);
EXPECT_TRUE(val1.matches(std::errc::invalid_argument));
EXPECT_TRUE(!val1.matches(std::error_condition{}));
EXPECT_TRUE(!val2.matches(std::error_condition{}));
EXPECT_NE(val1.error(), monero::error::none);
EXPECT_EQ(val2.error(), monero::error::none);
EXPECT_TRUE(val1.equal(monero::error::invalid_argument));
EXPECT_TRUE(!val2.equal(monero::error::none));
EXPECT_TRUE(!(val1 == monero::error::none));
EXPECT_TRUE(!(monero::error::none == val1));
EXPECT_TRUE(!(val2 == monero::error::none));
EXPECT_TRUE(!(monero::error::none == val2));
EXPECT_TRUE(val1 != monero::error::none);
EXPECT_TRUE(monero::error::none != val1);
EXPECT_TRUE(val2 != monero::error::none);
EXPECT_TRUE(monero::error::none != val2);
EXPECT_TRUE(val1.matches(monero::errc::invalid_argument));
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
val2 = val1;
@ -451,28 +451,28 @@ TEST(Expect, Assignment)
EXPECT_TRUE(!val2);
EXPECT_TRUE(!val1.has_value());
EXPECT_TRUE(!val2.has_value());
EXPECT_EQ(val1.error(), common_error::kInvalidArgument);
EXPECT_TRUE(val1 == common_error::kInvalidArgument);
EXPECT_TRUE(common_error::kInvalidArgument == val1);
EXPECT_EQ(val2.error(), common_error::kInvalidArgument);
EXPECT_TRUE(val2 == common_error::kInvalidArgument);
EXPECT_TRUE(common_error::kInvalidArgument == val2);
EXPECT_NE(val1.error(), std::error_code{});
EXPECT_NE(val2.error(), std::error_code{});
EXPECT_TRUE(val1.equal(common_error::kInvalidArgument));
EXPECT_TRUE(val2.equal(common_error::kInvalidArgument));
EXPECT_TRUE(!(val1 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val1));
EXPECT_TRUE(!(val2 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val2));
EXPECT_TRUE(val1 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val1);
EXPECT_TRUE(val2 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val2);
EXPECT_TRUE(val1.matches(std::errc::invalid_argument));
EXPECT_TRUE(val2.matches(std::errc::invalid_argument));
EXPECT_TRUE(!val1.matches(std::error_condition{}));
EXPECT_TRUE(!val2.matches(std::error_condition{}));
EXPECT_EQ(val1.error(), monero::error::invalid_argument);
EXPECT_TRUE(val1 == monero::error::invalid_argument);
EXPECT_TRUE(monero::error::invalid_argument == val1);
EXPECT_EQ(val2.error(), monero::error::invalid_argument);
EXPECT_TRUE(val2 == monero::error::invalid_argument);
EXPECT_TRUE(monero::error::invalid_argument == val2);
EXPECT_NE(val1.error(), monero::error::none);
EXPECT_NE(val2.error(), monero::error::none);
EXPECT_TRUE(val1.equal(monero::error::invalid_argument));
EXPECT_TRUE(val2.equal(monero::error::invalid_argument));
EXPECT_TRUE(!(val1 == monero::error::none));
EXPECT_TRUE(!(monero::error::none == val1));
EXPECT_TRUE(!(val2 == monero::error::none));
EXPECT_TRUE(!(monero::error::none == val2));
EXPECT_TRUE(val1 != monero::error::none);
EXPECT_TRUE(monero::error::none != val1);
EXPECT_TRUE(val2 != monero::error::none);
EXPECT_TRUE(monero::error::none != val2);
EXPECT_TRUE(val1.matches(monero::errc::invalid_argument));
EXPECT_TRUE(val2.matches(monero::errc::invalid_argument));
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
val1 = std::string{"barfoo"};
@ -485,24 +485,24 @@ TEST(Expect, Assignment)
EXPECT_STREQ(val1.value().c_str(), "barfoo");
EXPECT_TRUE(*val1 == "barfoo");
EXPECT_TRUE(boost::equals(val1->c_str(), "barfoo"));
EXPECT_EQ(val2.error(), common_error::kInvalidArgument);
EXPECT_TRUE(val2 == common_error::kInvalidArgument);
EXPECT_TRUE(common_error::kInvalidArgument == val2);
EXPECT_EQ(val1.error(), std::error_code{});
EXPECT_NE(val2.error(), std::error_code{});
EXPECT_TRUE(!val1.equal(std::error_code{}));
EXPECT_TRUE(val2.equal(common_error::kInvalidArgument));
EXPECT_TRUE(!(val1 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val1));
EXPECT_TRUE(!(val2 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val2));
EXPECT_TRUE(val1 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val1);
EXPECT_TRUE(val2 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val2);
EXPECT_TRUE(val2.matches(std::errc::invalid_argument));
EXPECT_TRUE(!val1.matches(std::error_condition{}));
EXPECT_TRUE(!val2.matches(std::error_condition{}));
EXPECT_EQ(val2.error(), monero::error::invalid_argument);
EXPECT_TRUE(val2 == monero::error::invalid_argument);
EXPECT_TRUE(monero::error::invalid_argument == val2);
EXPECT_EQ(val1.error(), monero::error::none);
EXPECT_NE(val2.error(), monero::error::none);
EXPECT_TRUE(!val1.equal(monero::error::none));
EXPECT_TRUE(val2.equal(monero::error::invalid_argument));
EXPECT_TRUE(!(val1 == monero::error::none));
EXPECT_TRUE(!(monero::error::none == val1));
EXPECT_TRUE(!(val2 == monero::error::none));
EXPECT_TRUE(!(monero::error::none == val2));
EXPECT_TRUE(val1 != monero::error::none);
EXPECT_TRUE(monero::error::none != val1);
EXPECT_TRUE(val2 != monero::error::none);
EXPECT_TRUE(monero::error::none != val2);
EXPECT_TRUE(val2.matches(monero::errc::invalid_argument));
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
val2 = val1;
@ -518,20 +518,20 @@ TEST(Expect, Assignment)
EXPECT_EQ(val2.value(), "barfoo");
EXPECT_TRUE(*val2 == "barfoo");
EXPECT_TRUE(boost::equals(val2->c_str(), "barfoo"));
EXPECT_EQ(val1.error(), std::error_code{});
EXPECT_EQ(val2.error(), std::error_code{});
EXPECT_TRUE(!val1.equal(std::error_code{}));
EXPECT_TRUE(!val2.equal(std::error_code{}));
EXPECT_TRUE(!(val1 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val1));
EXPECT_TRUE(!(val2 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val2));
EXPECT_TRUE(val1 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val1);
EXPECT_TRUE(val2 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val2);
EXPECT_TRUE(!val1.matches(std::error_condition{}));
EXPECT_TRUE(!val2.matches(std::error_condition{}));
EXPECT_EQ(val1.error(), monero::error::none);
EXPECT_EQ(val2.error(), monero::error::none);
EXPECT_TRUE(!val1.equal(monero::error::none));
EXPECT_TRUE(!val2.equal(monero::error::none));
EXPECT_TRUE(!(val1 == monero::error::none));
EXPECT_TRUE(!(monero::error::none == val1));
EXPECT_TRUE(!(val2 == monero::error::none));
EXPECT_TRUE(!(monero::error::none == val2));
EXPECT_TRUE(val1 != monero::error::none);
EXPECT_TRUE(monero::error::none != val1);
EXPECT_TRUE(val2 != monero::error::none);
EXPECT_TRUE(monero::error::none != val2);
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
}
TEST(Expect, AssignmentThrowsOnMove)
@ -555,14 +555,14 @@ TEST(Expect, AssignmentThrowsOnMove)
};
expect<throw_on_move> val1{expect<const char*>{"foobar"}};
expect<throw_on_move> val2{common_error::kInvalidArgument};
expect<throw_on_move> val2{monero::error::invalid_argument};
ASSERT_TRUE(val1.has_value());
ASSERT_TRUE(val2.has_error());
EXPECT_TRUE(!val1.has_error());
EXPECT_TRUE(!val2.has_value());
EXPECT_STREQ(val1->msg.c_str(), "foobar");
EXPECT_EQ(val2.error(), common_error::kInvalidArgument);
EXPECT_EQ(val2.error(), monero::error::invalid_argument);
EXPECT_THROW(val2 = std::move(val1), construct_error);
@ -571,7 +571,7 @@ TEST(Expect, AssignmentThrowsOnMove)
EXPECT_TRUE(!val1.has_error());
EXPECT_TRUE(!val2.has_value());
EXPECT_STREQ(val1->msg.c_str(), "foobar");
EXPECT_EQ(val2.error(), common_error::kInvalidArgument);
EXPECT_EQ(val2.error(), monero::error::invalid_argument);
EXPECT_THROW(val1 = expect<const char*>{"barfoo"}, assignment_error);
@ -580,7 +580,7 @@ TEST(Expect, AssignmentThrowsOnMove)
EXPECT_TRUE(!val1.has_error());
EXPECT_TRUE(!val2.has_value());
EXPECT_STREQ(val1->msg.c_str(), "foobar");
EXPECT_EQ(val2.error(), common_error::kInvalidArgument);
EXPECT_EQ(val2.error(), monero::error::invalid_argument);
EXPECT_NO_THROW(val2 = val1);
@ -620,9 +620,9 @@ TEST(Expect, EqualWithStrings)
EXPECT_TRUE(val1.equal(""));
EXPECT_TRUE(val2.equal("barfoo"));
EXPECT_TRUE(val3.equal(""));
EXPECT_TRUE(!val1.equal(std::error_code{}));
EXPECT_TRUE(!val2.equal(std::error_code{}));
EXPECT_TRUE(!val3.equal(std::error_code{}));
EXPECT_TRUE(!val1.equal(monero::error_code{}));
EXPECT_TRUE(!val2.equal(monero::error_code{}));
EXPECT_TRUE(!val3.equal(monero::error_code{}));
EXPECT_TRUE(val1 == "");
EXPECT_TRUE("" == val1);
EXPECT_TRUE(val2 == "barfoo");
@ -635,23 +635,23 @@ TEST(Expect, EqualWithStrings)
EXPECT_TRUE(!("barfoo" != val2));
EXPECT_TRUE(!(val3 != ""));
EXPECT_TRUE(!("" != val3));
EXPECT_TRUE(!(val1 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val1));
EXPECT_TRUE(!(val2 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val2));
EXPECT_TRUE(!(val3 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val3));
EXPECT_TRUE(val1 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val1);
EXPECT_TRUE(val2 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val2);
EXPECT_TRUE(val3 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val3);
EXPECT_TRUE(!val1.matches(std::error_condition{}));
EXPECT_TRUE(!val2.matches(std::error_condition{}));
EXPECT_TRUE(!val3.matches(std::error_condition{}));
val2 = make_error_code(common_error::kInvalidArgument);
EXPECT_TRUE(!(val1 == monero::error_code{}));
EXPECT_TRUE(!(monero::error_code{} == val1));
EXPECT_TRUE(!(val2 == monero::error_code{}));
EXPECT_TRUE(!(monero::error_code{} == val2));
EXPECT_TRUE(!(val3 == monero::error_code{}));
EXPECT_TRUE(!(monero::error_code{} == val3));
EXPECT_TRUE(val1 != monero::error_code{});
EXPECT_TRUE(monero::error_code{} != val1);
EXPECT_TRUE(val2 != monero::error_code{});
EXPECT_TRUE(monero::error_code{} != val2);
EXPECT_TRUE(val3 != monero::error_code{});
EXPECT_TRUE(monero::error_code{} != val3);
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
EXPECT_TRUE(!val3.matches(monero::error_condition{}));
val2 = make_error_code(monero::error::invalid_argument);
EXPECT_TRUE(!val1.equal(val2));
EXPECT_TRUE(val1.equal(val3));
@ -672,15 +672,15 @@ TEST(Expect, EqualWithStrings)
EXPECT_TRUE(val2 != val3);
EXPECT_TRUE(val3 != val2);
EXPECT_TRUE(!val1.equal(common_error::kInvalidArgument));
EXPECT_TRUE(val2.equal(common_error::kInvalidArgument));
EXPECT_TRUE(!val3.equal(common_error::kInvalidArgument));
EXPECT_TRUE(val2 == common_error::kInvalidArgument);
EXPECT_TRUE(common_error::kInvalidArgument == val2);
EXPECT_TRUE(!(val2 != common_error::kInvalidArgument));
EXPECT_TRUE(!(common_error::kInvalidArgument != val2));
EXPECT_TRUE(val2.matches(std::errc::invalid_argument));
EXPECT_TRUE(!val2.matches(std::error_condition{}));
EXPECT_TRUE(!val1.equal(monero::error::invalid_argument));
EXPECT_TRUE(val2.equal(monero::error::invalid_argument));
EXPECT_TRUE(!val3.equal(monero::error::invalid_argument));
EXPECT_TRUE(val2 == monero::error::invalid_argument);
EXPECT_TRUE(monero::error::invalid_argument == val2);
EXPECT_TRUE(!(val2 != monero::error::invalid_argument));
EXPECT_TRUE(!(monero::error::invalid_argument != val2));
EXPECT_TRUE(val2.matches(monero::errc::invalid_argument));
EXPECT_TRUE(!val2.matches(monero::error_condition{}));
val1 = expect<std::string>{"barfoo"};
@ -708,13 +708,13 @@ TEST(Expect, EqualWithStrings)
EXPECT_TRUE("barfoo" == val1);
EXPECT_TRUE(!(val1 != "barfoo"));
EXPECT_TRUE(!("barfoo" != val1));
EXPECT_TRUE(!val1.equal(common_error::kInvalidArgument));
EXPECT_TRUE(!(val1 == common_error::kInvalidArgument));
EXPECT_TRUE(!(common_error::kInvalidArgument == val1));
EXPECT_TRUE(!(val1 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val1));
EXPECT_TRUE(!val1.matches(std::error_condition{}));
EXPECT_TRUE(!val1.matches(std::errc::invalid_argument));
EXPECT_TRUE(!val1.equal(monero::error::invalid_argument));
EXPECT_TRUE(!(val1 == monero::error::invalid_argument));
EXPECT_TRUE(!(monero::error::invalid_argument == val1));
EXPECT_TRUE(!(val1 == monero::error_code{}));
EXPECT_TRUE(!(monero::error_code{} == val1));
EXPECT_TRUE(!val1.matches(monero::error_condition{}));
EXPECT_TRUE(!val1.matches(monero::errc::invalid_argument));
}
TEST(Expect, EqualWithVoid)
@ -724,40 +724,40 @@ TEST(Expect, EqualWithVoid)
EXPECT_TRUE(val1.equal(val2));
EXPECT_TRUE(val2.equal(val1));
EXPECT_TRUE(!val1.equal(std::error_code{}));
EXPECT_TRUE(!val2.equal(std::error_code{}));
EXPECT_TRUE(!val1.equal(monero::error_code{}));
EXPECT_TRUE(!val2.equal(monero::error_code{}));
EXPECT_TRUE(val1 == val2);
EXPECT_TRUE(val2 == val1);
EXPECT_TRUE(!(val1 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val1));
EXPECT_TRUE(!(val2 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val2));
EXPECT_TRUE(!(val1 == monero::error_code{}));
EXPECT_TRUE(!(monero::error_code{} == val1));
EXPECT_TRUE(!(val2 == monero::error_code{}));
EXPECT_TRUE(!(monero::error_code{} == val2));
EXPECT_TRUE(!(val1 != val2));
EXPECT_TRUE(!(val2 != val1));
EXPECT_TRUE(val1 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val1);
EXPECT_TRUE(!(val2 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val2));
EXPECT_TRUE(val1 != monero::error_code{});
EXPECT_TRUE(monero::error_code{} != val1);
EXPECT_TRUE(!(val2 == monero::error_code{}));
EXPECT_TRUE(!(monero::error_code{} == val2));
val2 = make_error_code(common_error::kInvalidArgument);
val2 = make_error_code(monero::error::invalid_argument);
EXPECT_TRUE(!val1.equal(val2));
EXPECT_TRUE(!val2.equal(val1));
EXPECT_TRUE(!val1.equal(common_error::kInvalidArgument));
EXPECT_TRUE(val2.equal(common_error::kInvalidArgument));
EXPECT_TRUE(!val2.equal(std::error_code{}));
EXPECT_TRUE(!val1.equal(monero::error::invalid_argument));
EXPECT_TRUE(val2.equal(monero::error::invalid_argument));
EXPECT_TRUE(!val2.equal(monero::error_code{}));
EXPECT_TRUE(!(val1 == val2));
EXPECT_TRUE(!(val2 == val1));
EXPECT_TRUE(val2 == common_error::kInvalidArgument);
EXPECT_TRUE(common_error::kInvalidArgument == val2);
EXPECT_TRUE(!(val2 == std::error_code{}));
EXPECT_TRUE(!(std::error_code{} == val2));
EXPECT_TRUE(val2 == monero::error::invalid_argument);
EXPECT_TRUE(monero::error::invalid_argument == val2);
EXPECT_TRUE(!(val2 == monero::error_code{}));
EXPECT_TRUE(!(monero::error_code{} == val2));
EXPECT_TRUE(val1 != val2);
EXPECT_TRUE(val2 != val1);
EXPECT_TRUE(!(val2 != common_error::kInvalidArgument));
EXPECT_TRUE(!(common_error::kInvalidArgument != val2));
EXPECT_TRUE(val2 != std::error_code{});
EXPECT_TRUE(std::error_code{} != val2);
EXPECT_TRUE(!(val2 != monero::error::invalid_argument));
EXPECT_TRUE(!(monero::error::invalid_argument != val2));
EXPECT_TRUE(val2 != monero::error_code{});
EXPECT_TRUE(monero::error_code{} != val2);
}
TEST(Expect, EqualNoCopies)
@ -802,7 +802,7 @@ TEST(Expect, EqualNoCopies)
EXPECT_TRUE(!(val1 != val3));
EXPECT_TRUE(!(val3 != val1));
expect<throw_on_copy> val4{common_error::kInvalidArgument};
expect<throw_on_copy> val4{monero::error::invalid_argument};
EXPECT_TRUE(!val4.equal(throw_on_copy{}));
EXPECT_TRUE(!(val4 == throw_on_copy{}));
@ -818,99 +818,99 @@ TEST(Expect, EqualNoCopies)
TEST(Expect, Macros) {
EXPECT_TRUE(
[] () -> ::common_error {
[] () -> ::monero::error {
MONERO_PRECOND(true);
return {common_error::kInvalidErrorCode};
} () == common_error::kInvalidErrorCode
return {monero::error::invalid_error_code};
} () == monero::error::invalid_error_code
);
EXPECT_TRUE(
[] () -> ::common_error {
[] () -> ::monero::error {
MONERO_PRECOND(false);
return {common_error::kInvalidErrorCode};
} () == common_error::kInvalidArgument
return {monero::error::invalid_error_code};
} () == monero::error::invalid_argument
);
EXPECT_TRUE(
[] () -> std::error_code {
[] () -> monero::error_code {
MONERO_PRECOND(true);
return {common_error::kInvalidErrorCode};
} () == common_error::kInvalidErrorCode
return {monero::error::invalid_error_code};
} () == monero::error::invalid_error_code
);
EXPECT_TRUE(
[] () -> std::error_code {
[] () -> monero::error_code {
MONERO_PRECOND(false);
return {common_error::kInvalidErrorCode};
} () == common_error::kInvalidArgument
return {monero::error::invalid_error_code};
} () == monero::error::invalid_argument
);
EXPECT_TRUE(
[] () -> expect<void> {
MONERO_PRECOND(true);
return {common_error::kInvalidErrorCode};
} () == common_error::kInvalidErrorCode
return {monero::error::invalid_error_code};
} () == monero::error::invalid_error_code
);
EXPECT_TRUE(
[] () -> expect<void> {
MONERO_PRECOND(false);
return {common_error::kInvalidErrorCode};
} () == common_error::kInvalidArgument
return {monero::error::invalid_error_code};
} () == monero::error::invalid_argument
);
EXPECT_TRUE(
[] () -> expect<int> {
MONERO_PRECOND(true);
return {common_error::kInvalidErrorCode};
} () == common_error::kInvalidErrorCode
return {monero::error::invalid_error_code};
} () == monero::error::invalid_error_code
);
EXPECT_TRUE(
[] () -> expect<int> {
MONERO_PRECOND(false);
return {common_error::kInvalidErrorCode};
} () == common_error::kInvalidArgument
return {monero::error::invalid_error_code};
} () == monero::error::invalid_argument
);
EXPECT_TRUE(
[] () -> std::error_code {
[] () -> monero::error_code {
MONERO_CHECK(expect<void>{});
return {common_error::kInvalidErrorCode};
} () == common_error::kInvalidErrorCode
return {monero::error::invalid_error_code};
} () == monero::error::invalid_error_code
);
EXPECT_TRUE(
[] () -> std::error_code {
MONERO_CHECK(expect<void>{common_error::kInvalidArgument});
return {common_error::kInvalidErrorCode};
} () == common_error::kInvalidArgument
[] () -> monero::error_code {
MONERO_CHECK(expect<void>{monero::error::invalid_argument});
return {monero::error::invalid_error_code};
} () == monero::error::invalid_argument
);
EXPECT_TRUE(
[] () -> expect<void> {
MONERO_CHECK(expect<void>{});
return {common_error::kInvalidErrorCode};
} () == common_error::kInvalidErrorCode
return {monero::error::invalid_error_code};
} () == monero::error::invalid_error_code
);
EXPECT_TRUE(
[] () -> expect<void> {
MONERO_CHECK(expect<void>{common_error::kInvalidArgument});
return {common_error::kInvalidErrorCode};
} () == common_error::kInvalidArgument
MONERO_CHECK(expect<void>{monero::error::invalid_argument});
return {monero::error::invalid_error_code};
} () == monero::error::invalid_argument
);
EXPECT_TRUE(
[] () -> expect<int> {
MONERO_CHECK(expect<void>{});
return {common_error::kInvalidErrorCode};
} () == common_error::kInvalidErrorCode
return {monero::error::invalid_error_code};
} () == monero::error::invalid_error_code
);
EXPECT_TRUE(
[] () -> expect<int> {
MONERO_CHECK(expect<void>{common_error::kInvalidArgument});
return {common_error::kInvalidErrorCode};
} () == common_error::kInvalidArgument
MONERO_CHECK(expect<void>{monero::error::invalid_argument});
return {monero::error::invalid_error_code};
} () == monero::error::invalid_argument
);
EXPECT_NO_THROW(MONERO_UNWRAP(success()));
EXPECT_NO_THROW(MONERO_UNWRAP(expect<void>{}));
EXPECT_NO_THROW(MONERO_UNWRAP(expect<int>{0}));
EXPECT_THROW(
MONERO_UNWRAP(expect<void>{common_error::kInvalidArgument}), std::system_error
MONERO_UNWRAP(expect<void>{monero::error::invalid_argument}), monero::system_error
);
EXPECT_THROW(
MONERO_UNWRAP(expect<int>{common_error::kInvalidArgument}), std::system_error
MONERO_UNWRAP(expect<int>{monero::error::invalid_argument}), monero::system_error
);
}

@ -212,7 +212,7 @@ TEST(LMDB, Table)
static_assert(test.flags == 0, "bad flags");
static_assert(&lmdb::less<unsigned> == test.key_cmp, "bad key_cmp");
static_assert(test.value_cmp == nullptr, "bad value_cmp");
EXPECT_TRUE(test.get_value<bytes>(MDB_val{}).matches(std::errc::invalid_argument));
EXPECT_TRUE(test.get_value<bytes>(MDB_val{}).matches(monero::errc::invalid_argument));
lmdb::basic_table<big_choice, one> test2{
"foo2", MDB_DUPSORT, &lmdb::compare<one>
@ -222,7 +222,7 @@ TEST(LMDB, Table)
EXPECT_EQ((MDB_DUPSORT | MDB_DUPFIXED), test2.flags);
EXPECT_EQ(&lmdb::less<unsigned long>, test2.key_cmp);
EXPECT_EQ(&lmdb::compare<one>, test2.value_cmp);
EXPECT_TRUE(test2.get_value<one>(MDB_val{}).matches(std::errc::invalid_argument));
EXPECT_TRUE(test2.get_value<one>(MDB_val{}).matches(monero::errc::invalid_argument));
one record{};
boost::iota(record.i.data, 0);
@ -238,18 +238,18 @@ TEST(LMDB, Table)
EXPECT_TRUE(boost::equal(record.j.data, j_copy.data));
EXPECT_TRUE(
test.get_key_stream(test_cursor{}).matches(std::errc::invalid_argument)
test.get_key_stream(test_cursor{}).matches(monero::errc::invalid_argument)
);
EXPECT_TRUE(
test2.get_key_stream(test_cursor{}).matches(std::errc::invalid_argument)
test2.get_key_stream(test_cursor{}).matches(monero::errc::invalid_argument)
);
EXPECT_TRUE(
test.get_value_stream(choice(0), test_cursor{}).matches(std::errc::invalid_argument)
test.get_value_stream(choice(0), test_cursor{}).matches(monero::errc::invalid_argument)
);
EXPECT_TRUE(
test2.get_value_stream(big_choice(0), test_cursor{}).matches(std::errc::invalid_argument)
test2.get_value_stream(big_choice(0), test_cursor{}).matches(monero::errc::invalid_argument)
);
}
@ -257,14 +257,14 @@ TEST(LMDB, InvalidDatabase)
{
lmdb::database test{lmdb::environment{}};
EXPECT_TRUE(test.resize().matches(std::errc::invalid_argument));
EXPECT_TRUE(test.create_read_txn().matches(std::errc::invalid_argument));
EXPECT_TRUE(test.reset_txn(lmdb::read_txn{}).matches(std::errc::invalid_argument));
EXPECT_TRUE(test.create_write_txn().matches(std::errc::invalid_argument));
EXPECT_TRUE(test.commit(lmdb::write_txn{}).matches(std::errc::invalid_argument));
EXPECT_TRUE(test.resize().matches(monero::errc::invalid_argument));
EXPECT_TRUE(test.create_read_txn().matches(monero::errc::invalid_argument));
EXPECT_TRUE(test.reset_txn(lmdb::read_txn{}).matches(monero::errc::invalid_argument));
EXPECT_TRUE(test.create_write_txn().matches(monero::errc::invalid_argument));
EXPECT_TRUE(test.commit(lmdb::write_txn{}).matches(monero::errc::invalid_argument));
EXPECT_TRUE(
test.try_write( [](MDB_txn&) { return success(); } ).matches(std::errc::invalid_argument)
test.try_write( [](MDB_txn&) { return success(); } ).matches(monero::errc::invalid_argument)
);
}

@ -1601,7 +1601,7 @@ TEST(zmq, error_codes)
std::addressof(net::zmq::make_error_code(0).category())
);
EXPECT_EQ(
std::make_error_condition(std::errc::not_a_socket),
make_error_condition(monero::errc::not_a_socket),
net::zmq::make_error_code(ENOTSOCK)
);
@ -1610,7 +1610,7 @@ TEST(zmq, error_codes)
{
MONERO_ZMQ_CHECK(zmq_msg_send(nullptr, nullptr, 0));
return success();
}().matches(std::errc::not_a_socket)
}().matches(monero::errc::not_a_socket)
);
bool thrown = false;
@ -1618,10 +1618,10 @@ TEST(zmq, error_codes)
{
MONERO_ZMQ_THROW("stuff");
}
catch (const std::system_error& e)
catch (const boost::system::system_error& e)
{
thrown = true;
EXPECT_EQ(std::make_error_condition(std::errc::not_a_socket), e.code());
EXPECT_EQ(make_error_condition(monero::errc::not_a_socket), e.code());
}
EXPECT_TRUE(thrown);
}

Loading…
Cancel
Save