Skip to main content

json_digest/
error.rs

1//! Error types for the json-digest crate.
2
3use alloc::string::String;
4use thiserror::Error;
5
6/// Errors that can occur during JSON digest operations.
7#[derive(Error, Debug)]
8pub enum JsonDigestError {
9    /// A JSON path did not start with `.`.
10    #[error("Path must start with '.' but it's: {path}")]
11    InvalidPathStart {
12        /// The offending path
13        path: String,
14    },
15
16    /// An unclosed bracket was found in a path.
17    #[error("Unclosed bracket in path: {path}")]
18    UnclosedBracket {
19        /// The offending path
20        path: String,
21    },
22
23    /// A non-composite type was passed to a digest function that requires objects or arrays.
24    #[error("Json digest is currently implemented only for composite types")]
25    NonCompositeType,
26
27    /// An internal inconsistency in the digest implementation.
28    #[error("{0}")]
29    Internal(String),
30
31    /// The input JSON string was not NFKD-normalized.
32    #[error("Json string to be digested must be normalized with Unicode NFKD")]
33    NonNormalizedInput,
34
35    /// JSON serialization/deserialization error.
36    #[error(transparent)]
37    Json(#[from] serde_json::Error),
38}
39
40/// Convenience alias for `Result<T, JsonDigestError>`.
41pub type Result<T> = core::result::Result<T, JsonDigestError>;