PrivMX Endpoint v2.8.0
Loading...
Searching...
No Matches
InboxException.hpp
1#ifndef _PRIVMXLIB_ENDPOINT_INBOX_EXT_EXCEPTION_HPP_
2#define _PRIVMXLIB_ENDPOINT_INBOX_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 inbox {
36// clang-format off
37#define ENDPOINT_INBOX_EXCEPTION_CODE 0x00070000
38
39DECLARE_SCOPE_ENDPOINT_EXCEPTION(EndpointInboxException, "Unknown endpoint inbox exception", "Inbox", 0x0007)
40
41#define INBOX_EXCEPTIONS(X) \
42 X(UnknownInboxHandleException, "Unknown inbox handle Id", 0x0002) \
43 X(InboxHandleIsNotTiedToInboxFileHandleException, "inboxHandle is not tied to inboxFileHandle", 0x0003) \
44 X(CannotExtractInboxCreatedEventException, "Cannot extract InboxCreatedEvent", 0x0004) \
45 X(CannotExtractInboxUpdatedEventException, "Cannot extract InboxUpdatedEvent", 0x0005) \
46 X(CannotExtractInboxDeletedEventException, "Cannot extract InboxDeletedEvent", 0x0006) \
47 X(FailedToExtractMessagePublicMetaException, "Failed to extract message public meta", 0x0009) \
48 X(InvalidEncryptedInboxDataVersionException, "Invalid version of encrypted Inbox data", 0x000F) \
49 X(CannotExtractInboxEntryCreatedEventException, "Cannot extract InboxEntryCreatedEvent", 0x0010) \
50 X(CannotExtractInboxEntryDeletedException, "Cannot extract InboxEntryDeleted", 0x0011) \
51 X(InboxPublicDataMismatchException, "Inbox public data mismatch", 0x0013) \
52 X(WritingToEntryInteruptedWrittenDataSmallerThenDeclaredException, "Writing to entry interupted. Written data smaller then declared", 0x0014) \
53 X(HandleIsUsedInInboxHandleException, "Handle is used in inbox handle", 0x0015) \
54 X(UnknownInboxFormatException, "Unknown Inbox format", 0x0020) \
55 X(InboxDataIntegrityException, "Failed inbox data integrity check", 0x0021) \
56 X(InboxModuleDoesNotSupportQueriesYetException, "Inbox module does not support queries yet.", 0x0099)
57
58#define PRIVMX_INBOX_DECLARE(NAME, MSG, CODE) DECLARE_ENDPOINT_EXCEPTION(EndpointInboxException, NAME, MSG, CODE)
59INBOX_EXCEPTIONS(PRIVMX_INBOX_DECLARE)
60#undef PRIVMX_INBOX_DECLARE
61
62// compile-time guard: codes are collected from the list above, never retyped
63#define PRIVMX_INBOX_CODE(NAME, MSG, CODE) NAME::FULL_CODE,
64static_assert(
65 privmx::endpoint::core::exceptionCodesUnique({INBOX_EXCEPTIONS(PRIVMX_INBOX_CODE)}),
66 "Duplicate exception code in inbox scope"
67);
68#undef PRIVMX_INBOX_CODE
69#undef INBOX_EXCEPTIONS
70// clang-format on
71} // namespace inbox
72} // namespace endpoint
73} // namespace privmx
74
75#undef DECLARE_SCOPE_ENDPOINT_EXCEPTION
76#undef DECLARE_ENDPOINT_EXCEPTION
77
78#endif // _PRIVMXLIB_ENDPOINT_INBOX_EXT_EXCEPTION_HPP_