This repository was archived by the owner on Feb 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patherror.rs
70 lines (66 loc) · 2.64 KB
/
error.rs
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* */
//! Not complete yet
//! This is where the error definitions can go
//! TODO: Implement proper error handling, this would include defining the error enum,
//! impl std::error::Error using `thiserror` and ensuring all errors are handled appropriately
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Invalid persisted data")]
InvalidPersistedData,
#[error("Rkv error: {0}")]
RkvError(rkv::StoreError),
#[error("IO error: {0}")]
IOError(#[from] std::io::Error),
#[error("JSON Error: {0}")]
JSONError(#[from] serde_json::Error),
#[error("EvaluationError: {0}")]
EvaluationError(String),
#[error("Invalid Expression - didn't evaluate to a bool")]
InvalidExpression,
#[error("InvalidFractionError: Should be between 0 and 1")]
InvalidFraction,
#[error("TryInto error: {0}")]
TryFromSliceError(#[from] std::array::TryFromSliceError),
#[error("Empty ratios!")]
EmptyRatiosError,
#[error("Attempt to access an element that is out of bounds")]
OutOfBoundsError,
#[error("Error parsing URL: {0}")]
UrlParsingError(#[from] url::ParseError),
#[error("Error sending request: {0}")]
RequestError(#[from] viaduct::Error),
#[error("UUID parsing error: {0}")]
UuidError(#[from] uuid::Error),
#[error("Error in network response: {0}")]
ResponseError(String),
#[error("Invalid experiments response received")]
InvalidExperimentFormat,
#[error("Invalid path: {0}")]
InvalidPath(String),
#[error("Internal error: {0}")]
InternalError(&'static str),
#[error("The experiment {0} does not exist")]
NoSuchExperiment(String),
#[error("The branch {0} does not exist for the experiment {1}")]
NoSuchBranch(String, String),
#[error("Server asked the client to back off ({0} seconds remaining)")]
BackoffError(u64),
#[error("Initialization of the database is not yet complete")]
DatabaseNotReady,
}
// This can be replaced with #[from] in the enum definition
// once rkv::StoreError impl std::error:Error (https://github.com/mozilla/rkv/issues/188)
impl From<rkv::StoreError> for Error {
fn from(store_error: rkv::StoreError) -> Self {
Error::RkvError(store_error)
}
}
impl<'a> From<jexl_eval::error::EvaluationError<'a>> for Error {
fn from(eval_error: jexl_eval::error::EvaluationError<'a>) -> Self {
Error::EvaluationError(eval_error.to_string())
}
}
pub type Result<T, E = Error> = std::result::Result<T, E>;