json0_rs/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum JsonError {
5    #[error("Unexpected error: {0}")]
6    UnexpectedError(String),
7    #[error("The parameter: \"{0}\" is invalid for reason: {1}")]
8    InvalidParameter(String, String),
9    #[error("Invalid operation: \"{0}\"")]
10    InvalidOperation(String),
11    /// Path must holding path elements (number or key) splited by ',' and all of the
12    /// elements must be surrounded with '[' and ']', eg: ['key1', 2, 'key2'].
13    /// If not, this error will be returned
14    #[error("Invalid path format")]
15    InvalidPathFormat,
16    /// Path elements can only be number or key. If not, this error will be returned
17    /// This error is simillar with InvalidPathFormat, but this error emphasize on
18    /// the validation of each path element not the whole path.
19    #[error("Invalid path element: {0}")]
20    InvalidPathElement(String),
21    #[error("Unexpetec value reached while traversing path")]
22    BadPath,
23    /// Error serializing or deserializing a value
24    #[error("Invalid JSON key or value")]
25    SerdeError(#[from] serde_json::Error),
26    #[error("Sub type name: {0} conflict with internal sub type name")]
27    ConflictSubType(String),
28}
29
30pub type Result<T> = std::result::Result<T, JsonError>;