1#ifndef _PRIVMXLIB_ENDPOINT_CORE_EXT_EXCEPTION_HPP_
2#define _PRIVMXLIB_ENDPOINT_CORE_EXT_EXCEPTION_HPP_
4#include "privmx/endpoint/core/Exception.hpp"
6#define DECLARE_SCOPE_ENDPOINT_EXCEPTION(NAME, MSG, SCOPE, CODE, ...) \
7 class NAME : public privmx::endpoint::core::Exception { \
9 static constexpr unsigned int SCOPE_CODE = (CODE); \
10 NAME() : privmx::endpoint::core::Exception(MSG, #NAME, SCOPE, (CODE << 16)) {} \
11 NAME(const std::string& description) \
12 : privmx::endpoint::core::Exception(MSG, #NAME, SCOPE, (CODE << 16), description) {} \
13 NAME(const std::string& msg, const std::string& name, unsigned int code) \
14 : privmx::endpoint::core::Exception(msg, name, SCOPE, (CODE << 16) | code, std::string()) {} \
15 NAME(const std::string& msg, const std::string& name, unsigned int code, const std::string& description) \
16 : privmx::endpoint::core::Exception(msg, name, SCOPE, (CODE << 16) | code, description) {} \
17 void rethrow() const override; \
19 inline void NAME::rethrow() const { \
23#define DECLARE_ENDPOINT_EXCEPTION(BASE_SCOPED, NAME, MSG, CODE, ...) \
24 class NAME : public BASE_SCOPED { \
26 static constexpr unsigned int FULL_CODE = (BASE_SCOPED::SCOPE_CODE << 16) | (CODE); \
27 NAME() : BASE_SCOPED(MSG, #NAME, CODE) {} \
28 NAME(const std::string& new_of_description) : BASE_SCOPED(MSG, #NAME, CODE, new_of_description) {} \
29 void rethrow() const override; \
31 inline void NAME::rethrow() const { \
39#define ENDPOINT_CORE_EXCEPTION_CODE 0x00010000
40#define ENDPOINT_CORE_API_EXCEPTION_CODE 0x00020000
42DECLARE_SCOPE_ENDPOINT_EXCEPTION(EndpointCoreException,
"Unknown endpoint core exception",
"Core", 0x0001)
44#define CORE_EXCEPTIONS(X) \
45 X(InvalidParamsException, "Invalid params", 0x0002) \
46 X(InvalidNumberOfParamsException, "Invalid number of params", 0x0003) \
47 X(UnsupportedTypeException, "Unsupported type", 0x0004) \
48 X(NoHandleFoundException, "No handle found", 0x0005) \
49 X(InvalidDataSignatureException, "Invalid data signature", 0x0007) \
50 X(UnsupportedSerializerBinaryFormatException, "Unsupported serializer binary format option", 0x0009) \
51 X(NotImplementedException, "Not Implemented", 0x000A) \
52 X(InvalidMethodException, "Invalid method", 0x000B) \
53 X(InvalidArgumentTypeException, "Invalid argument type", 0x000C) \
54 X(InvalidBackendRequestModeException, "Invalid BackendRequest mode", 0x000D) \
55 X(UserVerificationFailureException, "User verification failure", 0x000E) \
56 X(UserVerificationMethodUnhandledException, "UserVerifierInterface.verify() thrown an exception. Implementation of the UserVerifierInterface should provide adequate error handling.", 0x000F) \
57 X(MalformedEncryptionKeyException, "Malformed encryption key", 0x0010) \
58 X(UnknownEncryptionKeyVersionException, "Unknown encryption key", 0x0011) \
59 X(EncryptionKeyContainerValidationException, "Encryption key container validation error", 0x0012) \
60 X(DataIntegrityObjectDuplicatedException, "Duplicated data integrity object", 0x0013) \
61 X(MalformedDataIntegrityObjectException, "Malformed data integrity object", 0x0014) \
62 X(InvalidDataIntegrityObjectChecksumException, "Invalid data integrity object checksum", 0x0015) \
63 X(DataIntegrityObjectMismatchEncKeyException, "User key does not match with author public key in data integrity object", 0x0016) \
64 X(DataIntegrityObjectInvalidSignatureException, "Invalid data integrity object signature", 0x0017) \
65 X(KeyProviderRequestCompletedException, "KeyProvider request completed", 0x0018) \
66 X(MalformedVerifierResponseException, "Malformed verifier response", 0x0019) \
67 X(UnknownModuleEncryptionKeyException, "Module's enc key with given keyId does not exist.", 0x0020) \
68 X(ModulePublicDataMismatchException, "Module public data mismatch", 0x0021) \
69 X(InvalidEncryptedModuleDataVersionException, "Invalid version of encrypted module data", 0x0022) \
70 X(InvalidSubscriptionQueryException, "Invalid subscriptionQuery", 0x00024) \
71 X(InvalidSingletonsHolderStateException, "Invalid Singletons Holder state", 0x00025) \
72 X(EncryptionKeyValidationException, "Encryption key validation error", 0x0027) \
73 X(IncorrectKeyIdFormatException, "Incorrect key id format", 0x0028)
75#define PRIVMX_CORE_DECLARE(NAME, MSG, CODE) DECLARE_ENDPOINT_EXCEPTION(EndpointCoreException, NAME, MSG, CODE)
76CORE_EXCEPTIONS(PRIVMX_CORE_DECLARE)
77#undef PRIVMX_CORE_DECLARE
79DECLARE_SCOPE_ENDPOINT_EXCEPTION(EndpointConnectionException,
"Unknown endpoint connection exception",
"Connection", 0x0002)
81#define CONNECTION_EXCEPTIONS(X) \
82 X(NotInitializedException, "Endpoint not initialized", 0x0001) \
83 X(CannotExtractLibPlatformDisconnectedEventException, "Cannot extract LibPlatformDisconnectedEvent", 0x0002) \
84 X(CannotExtractLibConnectedEventException, "Cannot extract LibConnectedEvent", 0x0003) \
85 X(CannotExtractLibDisconnectedEventException, "Cannot extract LibDisconnectedEvent", 0x0004) \
86 X(DataBiggerThanDeclaredException, "Data bigger than declared", 0x0005) \
87 X(DataSmallerThanDeclaredException, "Data smaller than declared", 0x0006) \
88 X(DataDifferentThanDeclaredException, "Data different than declared", 0x0007) \
89 X(CannotExtractLibBreakEventException, "Cannot extract LibBreakEvent", 0x0008) \
90 X(ServerVersionMismatchException, "The Bridge Server and the PrivMX Endpoint library versions mismatch", 0x0009) \
91 X(CannotExtractCollectionChangedEventException, "Cannot extract CollectionChangedEvent", 0x000A) \
92 X(CannotExtractContextUserAddedEventException, "Cannot extract ContextUserAddedEvent", 0x000B) \
93 X(CannotExtractContextUserRemovedEventException, "Cannot extract ContextUserRemovedEvent", 0x000C) \
94 X(CannotExtractContextUsersStatusChangedEventException, "Cannot extract ContextUsersStatusChangedEvent", 0x000D) \
95 X(NotConnectedException, "Endpoint is not connected or not initialized", 0x000E)
97#define PRIVMX_CONNECTION_DECLARE(NAME, MSG, CODE) DECLARE_ENDPOINT_EXCEPTION(EndpointConnectionException, NAME, MSG, CODE)
98CONNECTION_EXCEPTIONS(PRIVMX_CONNECTION_DECLARE)
99#undef PRIVMX_CONNECTION_DECLARE
102#define PRIVMX_CODE(NAME, MSG, CODE) NAME::FULL_CODE,
104 privmx::endpoint::core::exceptionCodesUnique({
105 CORE_EXCEPTIONS(PRIVMX_CODE)
106 CONNECTION_EXCEPTIONS(PRIVMX_CODE)
108 "Duplicate exception code in core scope"
111#undef CORE_EXCEPTIONS
112#undef CONNECTION_EXCEPTIONS
118#undef DECLARE_SCOPE_ENDPOINT_EXCEPTION
119#undef DECLARE_ENDPOINT_EXCEPTION