ifw-daq 3.1.0
IFW Data Acquisition modules
Loading...
Searching...
No Matches
error.cpp
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 definitions for DAQ
7 */
8#include <daq/error.hpp>
9
10#include <ostream>
11
12#include <fmt/format.h>
13
14#include <daq/error/report.hpp>
15
16namespace daq {
17
18std::ostream& operator<<(std::ostream& os, ErrorPolicy policy) {
19 switch (policy) {
21 os << "Strict";
22 break;
24 os << "Tolerant";
25 break;
26 default:
27 os << "n/a";
28 }
29 return os;
30}
31
32DaqSourceError::DaqSourceError(std::string request, std::string source, std::string message)
33 : m_request(std::move(request)), m_source(std::move(source)), m_message(std::move(message)) {
34 m_formatted = fmt::format(
35 "Data source error: source={}, request={}, message={}", m_source, m_request, m_message);
36}
37
38auto DaqSourceErrors::Errors() const noexcept
39 -> std::vector<std::variant<DaqSourceError, std::exception_ptr>> const& {
40 return m_errors;
41}
42
43char const* DaqSourceError::what() const noexcept {
44 return m_formatted.c_str();
45}
46
47DaqSourceErrors::DaqSourceErrors(std::vector<std::exception_ptr> errors) {
48 std::copy(errors.begin(), errors.end(), std::back_inserter(m_errors));
49 Update();
50}
51
53 std::vector<std::variant<DaqSourceError, std::exception_ptr>> errors)
54 : m_errors(std::move(errors)) {
55 Update();
56}
57
58void DaqSourceErrors::Update() {
59 for (auto const& e : m_errors) {
60 if (auto const* ptr = std::get_if<DaqSourceError>(&e); ptr) {
61 m_what += ptr->what();
62 m_what += '\n';
63 } else if (auto const* ptr = std::get_if<std::exception_ptr>(&e); ptr) {
64 m_what += error::FormatException(*ptr);
65 }
66 }
67}
68
69char const* DaqSourceErrors::what() const noexcept {
70 return m_what.c_str();
71}
72
73} // namespace daq
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
DaqSourceError(std::string request, std::string source, std::string message)
Definition: error.cpp:32
std::string m_request
Definition: error.hpp:74
std::string m_formatted
Definition: error.hpp:77
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
DaqSourceErrors(std::vector< std::exception_ptr > errors)
Definition: error.cpp:47
Contains error related declarations for DAQ.
void FormatException(std::ostream &os, std::exception_ptr ptr)
Report without nesting.
Definition: report.cpp:79
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 ...