ifw-daq  3.0.0-pre2
IFW Data Acquisition modules
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 <stdexcept>
11 #include <vector>
12 #include <string>
13 #include <variant>
14 #include <iosfwd>
15 
16 
17 namespace daq {
18 
19 /**
20  * Error policy supported by certain operations.
21  *
22  * Fatal for any policy refers to the operation is aborted and reported as failed (typically using
23  * exceptions).
24  */
25 enum class ErrorPolicy {
26  /**
27  * Any error is considered fatal and may lead to the operation being aborted.
28  */
29  Strict = 0,
30 
31  /**
32  * Errors that can be ignored with partial completion of a command will be tolerated and
33  * is reported as successful.
34  */
35  Tolerant
36 };
37 
38 std::ostream& operator<<(std::ostream& os, ErrorPolicy policy);
39 
40 /**
41  * Started operation was aborted.
42  *
43  * Typically used to communicate that asynchronous operation has been aborted.
44  *
45  * @ingroup daq_common_libdaq
46  */
47 class DaqOperationAborted : public std::runtime_error {
48 public:
49  using std::runtime_error::runtime_error;
50 };
51 
52 /**
53  * Started operation timed out
54  *
55  * @ingroup daq_common_libdaq
56  */
57 class DaqOperationTimeout : public std::runtime_error {
58 public:
59  using std::runtime_error::runtime_error;
60 };
61 
62 /**
63  * Represents error in single source
64  *
65  * @ingroup daq_common_libdaq
66  */
67 class DaqSourceError : public virtual std::exception {
68 public:
69  DaqSourceError(std::string request, std::string source, std::string message);
70 
71  char const* what() const noexcept override; // NOLINT
72 
73  std::string m_request;
74  std::string m_source;
75  std::string m_message;
76  std::string m_formatted;
77 };
78 
79 /**
80  * Exception thrown to carry reply errors
81  *
82  * @ingroup daq_common_libdaq
83  */
84 class DaqSourceErrors : public virtual std::exception {
85 public:
86  DaqSourceErrors(std::vector<std::exception_ptr> errors);
87  DaqSourceErrors(std::vector<std::variant<DaqSourceError, std::exception_ptr>> errors);
88 
89  char const* what() const noexcept override; // NOLINT
90 
91  std::vector<std::variant<DaqSourceError, std::exception_ptr>> m_errors;
92 private:
93  void Update();
94  std::string m_what;
95 };
96 
97 
98 }
99 #endif // #ifndef OCF_DAQ_ERROR_HPP_
Started operation was aborted.
Definition: error.hpp:47
Started operation timed out.
Definition: error.hpp:57
Represents error in single source.
Definition: error.hpp:67
std::string m_source
Definition: error.hpp:74
std::string m_message
Definition: error.hpp:75
char const * what() const noexcept override
Definition: error.cpp:38
DaqSourceError(std::string request, std::string source, std::string message)
Definition: error.cpp:32
std::string m_request
Definition: error.hpp:73
std::string m_formatted
Definition: error.hpp:76
Exception thrown to carry reply errors.
Definition: error.hpp:84
char const * what() const noexcept override
Definition: error.cpp:64
DaqSourceErrors(std::vector< std::exception_ptr > errors)
Definition: error.cpp:42
std::vector< std::variant< DaqSourceError, std::exception_ptr > > m_errors
Definition: error.hpp:91
daqif::DaqStatus & operator<<(daqif::DaqStatus &status, daq::Status const &rhs)
Convert daq::Status -> daqif::DaqStatus by populating from rhs.
Definition: conversion.cpp:18
ErrorPolicy
Error policy supported by certain operations.
Definition: error.hpp:25
@ 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 ...