PrivMX Endpoint v2.8.0
Loading...
Searching...
No Matches
StoreException.hpp
1#ifndef _PRIVMXLIB_ENDPOINT_STORE_EXT_EXCEPTION_HPP_
2#define _PRIVMXLIB_ENDPOINT_STORE_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 store {
36// clang-format off
37#define ENDPOINT_STORE_EXCEPTION_CODE 0x00040000
38
39DECLARE_SCOPE_ENDPOINT_EXCEPTION(EndpointStoreException, "Unknown endpoint store exception", "Store", 0x0004)
40
41#define STORE_EXCEPTIONS(X) \
42 X(CannotExtractStoreCreatedEventException, "Cannot extract StoreCreatedEvent", 0x0002) \
43 X(CannotExtractStoreUpdatedEventException, "Cannot extract StoreUpdatedEvent", 0x0003) \
44 X(CannotExtractStoreStatsChangedEventException, "Cannot extract StoreStatsChangedEvent", 0x0004) \
45 X(CannotExtractStoreFileCreatedEventException, "Cannot extract StoreFileCreatedEvent", 0x0005) \
46 X(CannotExtractStoreFileUpdatedEventException, "Cannot extract StoreFileUpdatedEvent", 0x0006) \
47 X(CannotExtractStoreFileDeletedEventException, "Cannot extract StoreFileDeletedEvent", 0x0007) \
48 X(CannotExtractStoreDeletedEventException, "Cannot extract StoreDeletedEvent", 0x000D) \
49 X(UnsupportedCipherTypeException, "Unsupported cipher type", 0x0009) \
50 X(FileChunkInvalidChecksumException, "File chunk invalid checksum", 0x000B) \
51 X(FileChunkInvalidCipherChecksumException, "File chunk invalid cipher checksum", 0x000C) \
52 X(InvalidFileChunkSizeException, "Invalid file chunk size", 0x000E) \
53 X(InvalidFileReadHandleException, "Invalid file handle: handle is not FILE_READ_HANDLE", 0x000F) \
54 X(InvalidFileWriteHandleException, "Invalid file handle: handle is not FILE_WRITE_HANDLE", 0x0010) \
55 X(InvalidFileHandleException, "Invalid file handle: handle does not exist", 0x0011) \
56 X(FileVersionMismatchHandleClosedException, "File version mismatch, handle closed", 0x0013) \
57 X(PosOutOfBoundsException, "Pos out of bounds", 0x0014) \
58 X(FileCorruptedException, "File corrupted", 0x0015) \
59 X(NumberToBigForCPUArchitectureException, "Number is to big for this CPU Architecture", 0x0016) \
60 X(InvalidEncryptedStoreFileMetaVersionException, "Invalid version of encrypted file meta", 0x0019) \
61 X(UnknowStoreFormatException, "Unknown Store format", 0x001C) \
62 X(UnknowFileFormatException, "Unknown File format", 0x001D) \
63 X(FileFetchFailedException, "File fetch failed", 0x001E) \
64 X(FileVersionMismatchException, "File version mismatch", 0x001F) \
65 X(FilePublicDataMismatchException, "File public data mismatch", 0x0021) \
66 X(WritingToFileInteruptedWrittenDataSmallerThenDeclaredException, "Writing to file interupted. Written data smaller then declared", 0x0022) \
67 X(StoreDataIntegrityException, "Failed Store data integrity check", 0x0027) \
68 X(FileDataIntegrityException, "Failed file data integrity check", 0x0028) \
69 X(InvalidHashSizeException, "Invalid hash size", 0x0029) \
70 X(HashIndexOutOfBoundsException, "Hash index out of bounds", 0x002A) \
71 X(InvalidFileTopHashException, "Invalid file top hash", 0x002B) \
72 X(FileSyncFailedHandleCloseException, "File sync failed, handle closed", 0x002C) \
73 X(FileRandomWriteInternalException, "File random write internal Exception ", 0x002D)
74
75#define PRIVMX_STORE_DECLARE(NAME, MSG, CODE) DECLARE_ENDPOINT_EXCEPTION(EndpointStoreException, NAME, MSG, CODE)
76STORE_EXCEPTIONS(PRIVMX_STORE_DECLARE)
77#undef PRIVMX_STORE_DECLARE
78
79// compile-time guard: codes are collected from the list above, never retyped
80#define PRIVMX_STORE_CODE(NAME, MSG, CODE) NAME::FULL_CODE,
81static_assert(
82 privmx::endpoint::core::exceptionCodesUnique({STORE_EXCEPTIONS(PRIVMX_STORE_CODE)}),
83 "Duplicate exception code in store scope"
84);
85#undef PRIVMX_STORE_CODE
86#undef STORE_EXCEPTIONS
87// clang-format on
88
89} // namespace store
90} // namespace endpoint
91} // namespace privmx
92
93#undef DECLARE_SCOPE_ENDPOINT_EXCEPTION
94#undef DECLARE_ENDPOINT_EXCEPTION
95
96#endif // _PRIVMXLIB_ENDPOINT_STORE_EXT_EXCEPTION_HPP_