Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Error.hpp
1
2//------------------------------------------------------------------------------
3/*
4 This file is part of clio: https://github.com/XRPLF/clio
5 Copyright (c) 2024, the clio developers.
6
7 Permission to use, copy, modify, and distribute this software for any
8 purpose with or without fee is hereby granted, provided that the above
9 copyright notice and this permission notice appear in all copies.
10
11 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18*/
19//==============================================================================
20
21#pragma once
22
23#include <fmt/core.h>
24#include <fmt/std.h>
25
26#include <string>
27#include <utility>
28
29// for the static_assert at the bottom which fixes clang compilation:
30// see: https://godbolt.org/z/fzTjMd7G1 vs https://godbolt.org/z/jhKG7deen
31#include <any>
32#include <expected>
33
34namespace util::async {
35
46 ExecutionError(std::string tid, std::string msg)
47 : message{fmt::format("Thread {} exit with exception: {}", std::move(tid), std::move(msg))}
48 {
49 }
50
51 ExecutionError(ExecutionError const&) = default;
52 ExecutionError(ExecutionError&&) = default;
54 operator=(ExecutionError&&) = default;
56 operator=(ExecutionError const&) = default;
57
63 [[nodiscard]] operator char const*() const noexcept
64 {
65 return message.c_str();
66 }
67
68 std::string message;
69};
70
71// these are not the droids you are looking for...
72static_assert(std::is_copy_constructible_v<std::expected<std::any, ExecutionError>>);
73
74} // namespace util::async
This namespace implements an async framework built on top of execution contexts.
Definition AnyExecutionContext.hpp:36
Error channel type for async operation of any ExecutionContext.
Definition Error.hpp:39
ExecutionError(std::string tid, std::string msg)
Construct a new Execution Error object.
Definition Error.hpp:46