Ditto 4.11.1
 
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 \
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
42 * You can see more information about an error by calling @ref what().
43 */
44class DittoError : public std::exception {
45 std::string message;
46
47public:
48 DittoError();
49 explicit DittoError(dittoffi_error_t *ffi_error);
50 explicit DittoError(std::string msg);
51
57 char const *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// MARK: - Transaction errors
95
96DEFINE_EXCEPTION_CLASS_WITH_DOCS(
97 TransactionReadOnlyError,
98 R"(A mutating DQL query was executed in a read-only transaction.)",
99 friend class Transaction;)
100
101// MARK: - @ref Log.export_to_file errors
102
106class IOAlreadyExistsError : public DittoError {
107 friend class Log;
108
109public:
110 using DittoError::DittoError;
111};
112
114 * A file or directory could not be found.
115 */
116class IONotFoundError : public DittoError {
117 friend class Log;
118
119public:
120 using DittoError::DittoError;
121};
122
124 * The operation failed due to insufficient permissions.
125 */
126class IOPermissionDeniedError : public DittoError {
127 friend class Log;
128
129public:
130 using DittoError::DittoError;
131};
132
135 * details.
136 */
137class IOOperationFailedError : public DittoError {
138 friend class Log;
139
140public:
141 using DittoError::DittoError;
142};
143
144} // namespace ditto
145
146#endif
All errors that are thrown by the Ditto SDK are wrapped as a DittoError.
Definition Errors.hpp:42
char const * what() const noexcept override
Returns the explanatory string.
Definition Errors.cpp:40
Definition Errors.hpp:114
Definition Errors.hpp:135
Definition Errors.hpp:124
Main singleton (global instance) to tweak the behavior of Ditto's logging infrastructure.
Definition Log.hpp:29
Definition Presence.hpp:34
Provides access to Collections and a transaction API.
Definition Store.hpp:63
Definition Transaction.hpp:110