rsonpath/engine/
error.rs

1//! Error definitions and utilities for engine execution.
2use crate::{
3    error::{DepthError, InternalRsonpathError},
4    input::error::InputError,
5};
6use thiserror::Error;
7
8/// Error enum for all types of errors that can be reported
9/// during engine execution.
10///
11/// **NOTE**: Most errors are _not_ guaranteed to be raised for every
12/// JSON document that is malformed in the respective manner.
13/// The engine may ignore such errors and simply produce incorrect results
14/// for invalid documents.
15#[derive(Debug, Error)]
16pub enum EngineError {
17    /// Error while reading from the supplied [`Input`](crate::input::Input) implementation.
18    #[error(transparent)]
19    InputError(#[from] InputError),
20    /// Error while writing to the supplied [`Sink`](crate::result::Sink) implementation.
21    #[error("Error writing a result to sink: '{0}'")]
22    SinkError(#[source] Box<dyn std::error::Error + Send + Sync>),
23    /// Document depth fell below zero, which can only happen
24    /// if there are more closing than opening braces.
25    /// The inner [`usize`] value indicates the position of the mismatched closing character.
26    #[error("Mismatched closing character in the input JSON at position {0}.")]
27    DepthBelowZero(usize, #[source] DepthError),
28    /// The depth limit was reached -- the document is too nested.
29    /// The inner [`usize`] value indicates the position of the opening character
30    /// which caused the overflow.
31    #[error("Opening character at position {0} caused depth overflow.")]
32    DepthAboveLimit(usize, #[source] DepthError),
33    /// The engine reached end of the document while depth was positive.
34    /// This means that some of the opening characters do not have matching
35    /// closing characters.
36    #[error("Malformed input JSON; end of input was reached, but unmatched opening characters remained.")]
37    MissingClosingCharacter(),
38    /// The engine reached a structural character that should occur only in an object or list,
39    /// but there was no preceding opening character.
40    #[error("Malformed input JSON; structural characters present, but no opening character read.")]
41    MissingOpeningCharacter(),
42    /// The engine found a query match, but no value associated with it.
43    #[error("Malformed input JSON; a query match was found, but there was no associated value")]
44    MissingItem(),
45    /// An error occurred when trying to parse a member name terminated by a particular colon character.
46    /// The inner [`usize`] value should be set to the byte index of the colon.
47    #[error(
48        "Malformed member name in the input JSON; \
49        the colon at position {0} must be preceded by a string, but \
50        there are no matching double quote characters."
51    )]
52    MalformedStringQuotes(usize),
53    /// Engine error that occurred due to a known limitation.
54    #[error(transparent)]
55    NotSupported(#[from] crate::error::UnsupportedFeatureError),
56    /// Irrecoverable error due to a broken invariant or assumption.
57    /// The engine returns these instead of panicking.
58    #[error("EngineError: {0}")]
59    InternalError(
60        #[source]
61        #[from]
62        InternalRsonpathError,
63    ),
64}