ifw-daq 3.1.0
IFW Data Acquisition modules
Loading...
Searching...
No Matches
error.hpp
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup daq_common_libdaq
4 * @copyright 2022 ESO - European Southern Observatory
5 *
6 * @brief Contains error related declarations for DAQ
7 */
8#ifndef OCF_DAQ_ERROR_HPP_
9#define OCF_DAQ_ERROR_HPP_
10#include <iosfwd>
11#include <stdexcept>
12#include <string>
13#include <variant>
14#include <vector>
15
16#include <fmt/ostream.h>
17
18namespace daq {
19
20/**
21 * Error policy supported by certain operations.
22 *
23 * Fatal for any policy refers to the operation is aborted and reported as failed (typically using
24 * exceptions).
25 */
26enum class ErrorPolicy {
27 /**
28 * Any error is considered fatal and may lead to the operation being aborted.
29 */
30 Strict = 0,
31
32 /**
33 * Errors that can be ignored with partial completion of a command will be tolerated and
34 * is reported as successful.
35 */
37};
38
39std::ostream& operator<<(std::ostream& os, ErrorPolicy policy);
40
41/**
42 * Started operation was aborted.
43 *
44 * Typically used to communicate that asynchronous operation has been aborted.
45 *
46 * @ingroup daq_common_libdaq
47 */
48class DaqOperationAborted : public std::runtime_error {
49public:
50 using std::runtime_error::runtime_error;
51};
52
53/**
54 * Started operation timed out
55 *
56 * @ingroup daq_common_libdaq
57 */
58class DaqOperationTimeout : public std::runtime_error {
59public:
60 using std::runtime_error::runtime_error;
61};
62
63/**
64 * Represents error in single source
65 *
66 * @ingroup daq_common_libdaq
67 */
68class DaqSourceError : public virtual std::exception {
69public:
70 DaqSourceError(std::string request, std::string source, std::string message);
71
72 char const* what() const noexcept override; // NOLINT
73
74 std::string m_request;
75 std::string m_source;
76 std::string m_message;
77 std::string m_formatted;
78};
79
80/**
81 * Exception thrown to carry reply errors
82 *
83 * @ingroup daq_common_libdaq
84 */
85class DaqSourceErrors : public virtual std::exception {
86public:
87 DaqSourceErrors(std::vector<std::exception_ptr> errors);
88 DaqSourceErrors(std::vector<std::variant<DaqSourceError, std::exception_ptr>> errors);
89
90 char const* what() const noexcept override; // NOLINT
91
92 auto
93 Errors() const noexcept -> std::vector<std::variant<DaqSourceError, std::exception_ptr>> const&;
94
95private:
96 void Update();
97
98 std::vector<std::variant<DaqSourceError, std::exception_ptr>> m_errors;
99 std::string m_what;
100};
101
102} // namespace daq
103
104template <>
105struct fmt::formatter<daq::ErrorPolicy> : ostream_formatter {};
106
107#endif // #ifndef OCF_DAQ_ERROR_HPP_
Started operation was aborted.
Definition: error.hpp:48
Started operation timed out.
Definition: error.hpp:58
Represents error in single source.
Definition: error.hpp:68
std::string m_source
Definition: error.hpp:75
std::string m_message
Definition: error.hpp:76
char const * what() const noexcept override
Definition: error.cpp:43
std::string m_request
Definition: error.hpp:74
std::string m_formatted
Definition: error.hpp:77
Exception thrown to carry reply errors.
Definition: error.hpp:85
auto Errors() const noexcept -> std::vector< std::variant< DaqSourceError, std::exception_ptr > > const &
Definition: error.cpp:38
char const * what() const noexcept override
Definition: error.cpp:69
std::ostream & operator<<(std::ostream &os, AsyncProcessIf const &proc)
Formats proc representation in the form [<pid>] <args>
ErrorPolicy
Error policy supported by certain operations.
Definition: error.hpp:26
@ Strict
Any error is considered fatal and may lead to the operation being aborted.
@ Tolerant
Errors that can be ignored with partial completion of a command will be tolerated and is reported as ...