IRSOL
C++ code implementing socket server for interacting with Baumer camera.
irsol::protocol::Error Struct Reference

Represents an error response message from the server. More...

#include <error.hpp>

Public Member Functions

std::string toString () const
 Converts the error to a human-readable string.
 

Static Public Member Functions

template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, InMessage >, int > = 0>
static Error from (const T &msg, const std::string &description)
 Creates an error from a specific incoming message type.
 
static Error from (const InMessage &message, const std::string &description)
 Creates an error from a generic InMessage variant.
 

Public Attributes

std::string identifier
 The identifier related to the failed operation (e.g., the variable or command name).
 
InMessageKind source
 The kind of input message that triggered the error.
 
std::string description
 A descriptive message explaining the cause of the error.
 

Private Member Functions

 Error (const std::string &identifier, InMessageKind source, const std::string &description)
 

Detailed Description

Represents an error response message from the server.

An Error message is generated when a protocol input message fails to be parsed, interpreted, or executed correctly. It includes a reference identifier (if available), the type of message that caused the error, and a human-readable description of the issue.

Can be stored in a irsol::protocol::OutMessage variant.

Definition at line 35 of file error.hpp.

Constructor & Destructor Documentation

◆ Error()

irsol::protocol::Error::Error ( const std::string &  identifier,
InMessageKind  source,
const std::string &  description 
)
private

Definition at line 10 of file error.cpp.

12{}
std::string validateIdentifier(const std::string &identifier)
Validate that a string is a valid protocol identifier.
Definition utils.hpp:55
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

Member Function Documentation

◆ from() [1/2]

Error irsol::protocol::Error::from ( const InMessage message,
const std::string &  description 
)
static

Creates an error from a generic InMessage variant.

Parameters
messageThe original message variant.
descriptionThe explanation of the error.
Returns
An Error instance describing the issue.

Definition at line 25 of file error.cpp.

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}
auto value

◆ from() [2/2]

template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant_v< T, InMessage >, int > = 0>
static Error irsol::protocol::Error::from ( const T &  msg,
const std::string &  description 
)
inlinestatic

Creates an error from a specific incoming message type.

This templated overload supports Assignment, Command, and Inquiry input types.

Template Parameters
TThe incoming message type.
Parameters
msgThe message that caused the error.
descriptionThe explanation of the error.
Returns
An Error instance describing the issue.

Definition at line 63 of file error.hpp.

64 {
65 if constexpr(std::is_same_v<T, Assignment>) {
67 } else if constexpr(std::is_same_v<T, Inquiry>) {
68 return Error(msg.identifier, InMessageKind::INQUIRY, description);
69 } else if constexpr(std::is_same_v<T, Command>) {
70 return Error(msg.identifier, InMessageKind::COMMAND, description);
71 } else {
72 IRSOL_MISSING_TEMPLATE_SPECIALIZATION(T, "Error::from<T>()");
73 }
74 }
#define IRSOL_MISSING_TEMPLATE_SPECIALIZATION(T, funcNameLiteral)
Emits a compile-time error when no template specialization is available.
Definition macros.hpp:173
Error(const std::string &identifier, InMessageKind source, const std::string &description)
Definition error.cpp:10
auto msg

◆ toString()

std::string irsol::protocol::Error::toString ( ) const

Converts the error to a human-readable string.

Returns
A string representation of the error.

Definition at line 15 of file error.cpp.

16{
17 std::ostringstream oss;
18 oss << "Error{"
19 << "identifier: '" << identifier << "', source: " << InMessageKindToString(source)
20 << ", description: '" << description << "'}";
21 return oss.str();
22}
constexpr const char * InMessageKindToString(InMessageKind kind)
Converts an InMessageKind enum to a human-readable string.
Definition variants.hpp:59

Member Data Documentation

◆ description

std::string irsol::protocol::Error::description

A descriptive message explaining the cause of the error.

Definition at line 44 of file error.hpp.

◆ identifier

std::string irsol::protocol::Error::identifier

The identifier related to the failed operation (e.g., the variable or command name).

Definition at line 38 of file error.hpp.

◆ source

InMessageKind irsol::protocol::Error::source

The kind of input message that triggered the error.

Definition at line 41 of file error.hpp.


The documentation for this struct was generated from the following files: