1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#![forbid(unsafe_code)]
#![warn(
clippy::cargo,
missing_docs,
clippy::nursery,
clippy::pedantic,
future_incompatible,
rust_2018_idioms,
)]
#![allow(
clippy::missing_errors_doc,
clippy::option_if_let_else,
clippy::module_name_repetitions,
)]
pub mod permissions;
pub mod admin;
pub mod connection;
pub mod document;
pub mod limits;
pub mod schema;
pub mod transaction;
pub mod keyvalue;
pub mod custom_api;
#[cfg(feature = "networking")]
pub mod networking;
pub mod pubsub;
use std::string::FromUtf8Error;
pub use actionable;
pub use arc_bytes;
pub use async_trait;
pub use circulate;
pub use num_traits;
pub use ordered_varint;
use schema::{view, CollectionName, SchemaName, ViewName};
use serde::{Deserialize, Serialize};
pub use transmog;
pub use transmog_pot;
use crate::{document::Header, schema::InsertError};
#[derive(Clone, thiserror::Error, Debug, Serialize, Deserialize)]
pub enum Error {
#[error(
"database '{database_name}' was created with schema '{stored_schema}', not '{schema}'"
)]
SchemaMismatch {
database_name: String,
schema: SchemaName,
stored_schema: SchemaName,
},
#[error("schema '{0}' was already registered")]
SchemaAlreadyRegistered(SchemaName),
#[error("schema '{0}' is not registered")]
SchemaNotRegistered(SchemaName),
#[error("invalid database name: {0}")]
InvalidDatabaseName(String),
#[error("database '{0}' was not found")]
DatabaseNotFound(String),
#[error("a database with name '{0}' already exists")]
DatabaseNameAlreadyTaken(String),
#[error("error from storage: {0}")]
Database(String),
#[error("error serializing: {0}")]
Serialization(String),
#[error("error from server: {0}")]
Server(String),
#[error("a transport error occurred: '{0}'")]
Transport(String),
#[cfg(feature = "websockets")]
#[error("a websocket error occurred: '{0}'")]
Websocket(String),
#[cfg(feature = "networking")]
#[error("a networking error occurred: '{0}'")]
Networking(networking::Error),
#[error("an io error occurred: '{0}'")]
Io(String),
#[error("a configuration error occurred: '{0}'")]
Configuration(String),
#[error("an io error in the client: '{0}'")]
Client(String),
#[error("attempted to access a collection not registered with this schema")]
CollectionNotFound,
#[error("attempted to define a collection that already has been defined")]
CollectionAlreadyDefined,
#[error("the requested document id {1} from collection {0} was not found")]
DocumentNotFound(CollectionName, u64),
#[error("a conflict was detected while updating document id {1} from collection {0}")]
DocumentConflict(CollectionName, u64),
#[error("a unique key violation occurred: document `{existing_document}` already has the same key as `{conflicting_document}` for {view}")]
UniqueKeyViolation {
view: ViewName,
conflicting_document: Header,
existing_document: Header,
},
#[error("an invalid name was used in a schema: {0}")]
InvalidName(#[from] schema::InvalidNameError),
#[error("permission error: {0}")]
PermissionDenied(#[from] actionable::PermissionDenied),
#[error("error with password: {0}")]
Password(String),
#[error("user not found")]
UserNotFound,
#[error("invalid string: {0}")]
InvalidUnicode(String),
#[error("invalid credentials")]
InvalidCredentials,
#[error("reduce is unimplemented")]
ReduceUnimplemented,
#[error("floating point operation yielded NaN")]
NotANumber,
}
impl From<pot::Error> for Error {
fn from(err: pot::Error) -> Self {
Self::Serialization(err.to_string())
}
}
impl<T> From<InsertError<T>> for Error {
fn from(err: InsertError<T>) -> Self {
err.error
}
}
impl From<view::Error> for Error {
fn from(err: view::Error) -> Self {
Self::Database(err.to_string())
}
}
impl From<FromUtf8Error> for Error {
fn from(err: FromUtf8Error) -> Self {
Self::InvalidUnicode(err.to_string())
}
}
#[cfg(any(feature = "test-util", test))]
#[allow(missing_docs)]
pub mod test_util;
#[cfg(feature = "encryption")]
pub const ENCRYPTION_ENABLED: bool = true;
#[cfg(not(feature = "encryption"))]
pub const ENCRYPTION_ENABLED: bool = false;
pub trait AnyError: std::error::Error + Send + Sync + 'static {}
impl<T> AnyError for T where T: std::error::Error + Send + Sync + 'static {}