IRSOL
C++ code implementing socket server for interacting with Baumer camera.
error.cpp
Go to the documentation of this file.
1
3
5
6#include <sstream>
7
8namespace irsol {
9namespace protocol {
10Error::Error(const std::string& identifier, InMessageKind source, const std::string& description)
11 : identifier(utils::validateIdentifier(identifier)), source(source), description(description)
12{}
13
14std::string
16{
17 std::ostringstream oss;
18 oss << "Error{"
19 << "identifier: '" << identifier << "', source: " << InMessageKindToString(source)
20 << ", description: '" << description << "'}";
21 return oss.str();
22}
23
25Error::from(const InMessage& message, const std::string& description)
26{
27 return std::visit(
28 [&description](auto&& value) -> Error {
29 using T = std::decay_t<decltype(value)>;
30 return Error::from<T>(value, description);
31 },
32 message);
33}
34
35} // namespace protocol
36} // namespace irsol
Protocol error message representation.
std::variant< Assignment, Inquiry, Command > InMessage
Variant type representing any incoming message.
Definition variants.hpp:86
constexpr const char * InMessageKindToString(InMessageKind kind)
Converts an InMessageKind enum to a human-readable string.
Definition variants.hpp:59
InMessageKind
Represents the type of an incoming message.
Definition variants.hpp:45
Utility functions for protocol string handling and validation in the irsol library.
Represents an error response message from the server.
Definition error.hpp:36
Error(const std::string &identifier, InMessageKind source, const std::string &description)
Definition error.cpp:10
InMessageKind source
The kind of input message that triggered the error.
Definition error.hpp:41
std::string identifier
The identifier related to the failed operation (e.g., the variable or command name).
Definition error.hpp:38
std::string description
A descriptive message explaining the cause of the error.
Definition error.hpp:44
static Error from(const T &msg, const std::string &description)
Creates an error from a specific incoming message type.
Definition error.hpp:63
std::string toString() const
Converts the error to a human-readable string.
Definition error.cpp:15
auto value
auto description