PrivMX Endpoint v2.8.0
Loading...
Searching...
No Matches
KvdbException.hpp
1#ifndef _PRIVMXLIB_ENDPOINT_KVDB_EXT_EXCEPTION_HPP_
2#define _PRIVMXLIB_ENDPOINT_KVDB_EXT_EXCEPTION_HPP_
3
4#include "privmx/endpoint/core/Exception.hpp"
5
6#define DECLARE_SCOPE_ENDPOINT_EXCEPTION(NAME, MSG, SCOPE, CODE, ...) \
7 class NAME : public privmx::endpoint::core::Exception { \
8 public: \
9 static constexpr unsigned int SCOPE_CODE = (CODE); \
10 NAME() : privmx::endpoint::core::Exception(MSG, #NAME, SCOPE, (CODE << 16)) {} \
11 NAME(const std::string& msg, const std::string& name, unsigned int code) \
12 : privmx::endpoint::core::Exception(msg, name, SCOPE, (CODE << 16) | code, std::string()) {} \
13 NAME(const std::string& msg, const std::string& name, unsigned int code, const std::string& description) \
14 : privmx::endpoint::core::Exception(msg, name, SCOPE, (CODE << 16) | code, description) {} \
15 void rethrow() const override; \
16 }; \
17 inline void NAME::rethrow() const { \
18 throw *this; \
19 };
20
21#define DECLARE_ENDPOINT_EXCEPTION(BASE_SCOPED, NAME, MSG, CODE, ...) \
22 class NAME : public BASE_SCOPED { \
23 public: \
24 static constexpr unsigned int FULL_CODE = (BASE_SCOPED::SCOPE_CODE << 16) | (CODE); \
25 NAME() : BASE_SCOPED(MSG, #NAME, CODE) {} \
26 NAME(const std::string& new_of_description) : BASE_SCOPED(MSG, #NAME, CODE, new_of_description) {} \
27 void rethrow() const override; \
28 }; \
29 inline void NAME::rethrow() const { \
30 throw *this; \
31 };
32
33namespace privmx {
34namespace endpoint {
35namespace kvdb {
36// clang-format off
37#define ENDPOINT_KVDB_EXCEPTION_CODE 0x000A0000
38
39DECLARE_SCOPE_ENDPOINT_EXCEPTION(EndpointKvdbException, "Unknown endpoint kvdb exception", "Kvdb", 0x000A)
40
41#define KVDB_EXCEPTIONS(X) \
42 X(CannotExtractKvdbCreatedEventException, "Cannot extract KvdbCreatedEvent", 0x0002) \
43 X(CannotExtractKvdbUpdatedEventException, "Cannot extract KvdbUpdatedEvent", 0x0003) \
44 X(CannotExtractKvdbDeletedEventException, "Cannot extract KvdbDeletedEvent", 0x0004) \
45 X(CannotExtractKvdbStatsEventException, "Cannot extract KvdbStatsEvent", 0x0005) \
46 X(CannotExtractKvdbNewEntryEventException, "Cannot extract KvdbNewEntryEvent", 0x0006) \
47 X(CannotExtractKvdbDeletedEntryEventException, "Cannot extract KvdbDeletedEntryEvent", 0x0007) \
48 X(CannotExtractKvdbEntryUpdatedEventException, "Cannot extract KvdbKvdbEntryUpdatedEvent", 0x0008) \
49 X(KvdbEntryPublicDataMismatchException, "Kvdb entry public data mismatch", 0x000A) \
50 X(InvalidEncryptedKvdbEntryDataVersionException, "Invalid version of encrypted kvdb entry data", 0x000B) \
51 X(UnknownKvdbFormatException, "Unknown kvdb format", 0x000F) \
52 X(UnknownKvdbEntryFormatException, "Unknown item format", 0x0010) \
53 X(KvdbDataIntegrityException, "Failed kvdb data integrity check", 0x0011) \
54 X(KvdbEntryDataIntegrityException, "Failed kvdb entry data integrity check", 0x0012)
55
56#define PRIVMX_KVDB_DECLARE(NAME, MSG, CODE) DECLARE_ENDPOINT_EXCEPTION(EndpointKvdbException, NAME, MSG, CODE)
57KVDB_EXCEPTIONS(PRIVMX_KVDB_DECLARE)
58#undef PRIVMX_KVDB_DECLARE
59
60// compile-time guard: codes are collected from the list above, never retyped
61#define PRIVMX_KVDB_CODE(NAME, MSG, CODE) NAME::FULL_CODE,
62static_assert(
63 privmx::endpoint::core::exceptionCodesUnique({KVDB_EXCEPTIONS(PRIVMX_KVDB_CODE)}),
64 "Duplicate exception code in kvdb scope"
65);
66#undef PRIVMX_KVDB_CODE
67#undef KVDB_EXCEPTIONS
68// clang-format on
69} // namespace kvdb
70} // namespace endpoint
71} // namespace privmx
72
73#undef DECLARE_SCOPE_ENDPOINT_EXCEPTION
74#undef DECLARE_ENDPOINT_EXCEPTION
75
76#endif // _PRIVMXLIB_ENDPOINT_KVDB_EXT_EXCEPTION_HPP_