Ditto 4.7.0
Loading...
Searching...
No Matches
Errors.hpp
1#ifndef _DITTO_ERRORS_
2#define _DITTO_ERRORS_
3
4#include <exception>
5#include <string>
6
7struct dittoffi_error;
8typedef dittoffi_error dittoffi_error_t;
9
10#define DEFINE_EXCEPTION_CLASS_WITH_DOCS(EXCEPTION_NAME, DOCSTRING, ...) \
11
13 \
14 class EXCEPTION_NAME : public std::exception { \
15 __VA_ARGS__ \
16 std::string message; \
17 EXCEPTION_NAME(); \
18 \
19 public: \
20 const char *what() const noexcept override { return message.c_str(); } \
21 };
22
23// TODO(Ham): Remove this in favour of the one above, but only when all errors
24// have been documented and we've figured out how Doxygen can pick them up to
25// document them
26#define DEFINE_EXCEPTION_CLASS(EXCEPTION_NAME, ...) \
27 class EXCEPTION_NAME : public std::exception { \
28 __VA_ARGS__ \
29 std::string message; \
30 EXCEPTION_NAME(); \
31 \
32 public: \
33 const char *what() const noexcept override { return message.c_str(); } \
34 };
35
36namespace ditto {
37
44class DittoError : public std::exception {
45 std::string message;
46
47public:
48 DittoError();
49 DittoError(dittoffi_error_t *ffi_error);
50 explicit DittoError(std::string msg);
51
57 const char *what() const noexcept override;
58};
59
60// MARK: - More specific errors
61
62// MARK: - Attachment fetch errors
63
64DEFINE_EXCEPTION_CLASS(AttachmentNotFoundError,
65 friend class AttachmentFetcherCtx;)
66DEFINE_EXCEPTION_CLASS(AttachmentTokenInvalidError,
67 friend class AttachmentFetcherCtx;)
68DEFINE_EXCEPTION_CLASS(FailedToFetchAttachmentError,
69 friend class AttachmentFetcherCtx;)
70
71// MARK: - Attachment creation errors
72
73DEFINE_EXCEPTION_CLASS(AttachmentFilePermissionDeniedError, friend class Store;)
74DEFINE_EXCEPTION_CLASS(AttachmentFileNotFoundError, friend class Store;)
75DEFINE_EXCEPTION_CLASS(FailedToCreateAttachmentError, friend class Store;)
76
77// MARK: - Validation errors
78
79// TODO(Ham): Make it so that these classes get documented by Doxygen. They
80// aren't getting picked up currently
81DEFINE_EXCEPTION_CLASS_WITH_DOCS(
82 ValidationNotAMapError,
83 R"(The object is not a map where a map is expected.)",
84 friend class Presence;)
85DEFINE_EXCEPTION_CLASS_WITH_DOCS(
86 ValidationSizeLimitExceededError,
87 R"(The size limit for some piece of data has been exceeded.)",
88 friend class Presence;)
89DEFINE_EXCEPTION_CLASS_WITH_DOCS(
90 ValidationNotJSONCompatibleError,
91 R"(The object is or contain(s) types that aren't JSON compatible.)",
92 friend class Presence;)
93
94} // namespace ditto
95
96#endif
const char * what() const noexcept override
Returns the explanatory string.
Definition Errors.cpp:40