5#ifndef ASTARTE_DEVICE_SDK_ERRORS_H
6#define ASTARTE_DEVICE_SDK_ERRORS_H
13#if defined(ASTARTE_USE_TL_EXPECTED)
14#include "tl/expected.hpp"
19#include "astarte_device_sdk/formatter.hpp"
23#if defined(ASTARTE_USE_TL_EXPECTED)
24namespace astarte_tl = ::tl;
26namespace astarte_tl = ::std;
58 auto message() const -> const std::
string&;
63 auto
type() const -> const std::
string&;
110 static constexpr std::string_view k_type_ =
"AstarteInternalError";
131 static constexpr std::string_view k_type_ =
"AstarteFileOpenError";
152 static constexpr std::string_view k_type_ =
"AstarteInvalidInputError";
173 static constexpr std::string_view k_type_ =
"AstarteOperationRefusedError";
208 static constexpr std::string_view k_type_ =
"AstarteGrpcLibError";
229 static constexpr std::string_view k_type_ =
"AstarteMsgHubError";
246 template <
typename ParseContext>
247 constexpr auto parse(ParseContext& ctx)
const {
257 template <
typename FormatContext>
258 auto format(
const AstarteDeviceSdk::AstarteErrorBase& err, FormatContext& ctx)
const {
259 auto out = astarte_fmt::format_to(ctx.out(),
"{}: {}", err.
type(), err.
message());
261 std::string indent =
"";
262 const AstarteDeviceSdk::AstarteErrorBase* current = &err;
265 out = astarte_fmt::format_to(out,
"\n{}-> {}: {}", indent, nested->type(), nested->message());
266 current = nested.get();
277struct astarte_fmt::formatter<AstarteDeviceSdk::
AstarteError> {
283 template <
typename ParseContext>
284 constexpr auto parse(ParseContext& ctx)
const {
294 template <
typename FormatContext>
297 [&ctx](
const auto& err) {
298 const auto& base_err =
static_cast<const AstarteDeviceSdk::AstarteErrorBase&
>(err);
299 return astarte_fmt::format_to(ctx.out(),
"{}", base_err);
auto message() const -> const std::string &
Return the message encapsulated in the error.
virtual ~AstarteErrorBase()
Destructor for the Astarte error.
auto nested_error() const -> const std::shared_ptr< AstarteErrorBase > &
Return the nested error.
auto type() const -> const std::string &
Return the type encapsulated in the error.
AstarteErrorBase(std::string_view type, std::string_view message)
Constructor for the Astarte error.
Specific error for when a file cannot be opened.
Definition errors.hpp:116
AstarteFileOpenError(std::string_view filename, const AstarteError &other)
Nested error constructor.
AstarteFileOpenError(std::string_view filename)
Standard error constructor.
Error reported by the gRPC transport library.
Definition errors.hpp:179
AstarteGrpcLibError(std::string_view message, const AstarteError &other)
Nested error constructor.
AstarteGrpcLibError(std::uint64_t code, std::string_view message)
Error constructor including gRPC error codes.
AstarteGrpcLibError(std::uint64_t code, std::string_view message, const AstarteError &other)
Nested error constructor including gRPC error codes.
AstarteGrpcLibError(std::string_view message)
Standard error constructor.
Specific error for when an operation failed due to an internal error.
Definition errors.hpp:95
AstarteInternalError(std::string_view message, const AstarteError &other)
Nested error constructor.
AstarteInternalError(std::string_view message)
Standard error constructor.
Error reported by the Astarte message hub library.
Definition errors.hpp:214
AstarteMsgHubError(std::string_view message)
Standard error constructor.
AstarteMsgHubError(std::string_view message, const AstarteError &other)
Nested error constructor.
Attempted an operation which is not permitted according to the current device status.
Definition errors.hpp:158
AstarteOperationRefusedError(std::string_view message, const AstarteError &other)
Nested error constructor.
AstarteOperationRefusedError(std::string_view message)
Standard error constructor.
Umbrella namespace for the Astarte device SDK.
Definition data.hpp:23
std::variant< AstarteInternalError, AstarteFileOpenError, AstarteInvalidInputError, AstarteOperationRefusedError, AstarteGrpcLibError, AstarteMsgHubError > AstarteError
A variant type representing any possible error from the Astarte device library.
Definition errors.hpp:41