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
//! Error definitions and utilities for engine execution.
use thiserror::Error;
/// Error enum for all types of errors that can be reported
/// during engine execution.
///
/// **NOTE**: These error are _not_ guaranteed to be raised for every
/// JSON document that is malformed in the respective manner.
/// The engine may ignore such errors and simply produce incorrect results
/// for invalid documents.
#[derive(Debug, Error)]
pub enum EngineError {
/// Document depth fell below zero, which can only happen
/// if there are more closing than opening braces.
/// The inner [`usize`] value indicates the position of the mismatched closing character.
#[error("Mismatched closing character in the input JSON at position {0}.")]
DepthBelowZero(usize, #[source] DepthError),
/// The depth limit was reached -- the document is too nested.
/// The inner [`usize`] value indicates the position of the opening character
/// which caused the overflow.
#[error("Opening character at position {0} caused depth overflow.")]
DepthAboveLimit(usize, #[source] DepthError),
/// The engine reached end of the document while depth was positive.
/// This means that some of the opening characters do not have matching
/// closing characters.
#[error("Malformed input JSON; end of input was reached, but unmatched opening characters remained.")]
MissingClosingCharacter(),
/// An error occurred when trying to parse a label terminated by a particular colon character.
/// The inner [`usize`] value should be set to the byte index of the colon.
#[error(
"Malformed label in the input JSON; \
the colon at position {0} must be preceded by a string, but \
there are no matching double quote characters."
)]
MalformedLabelQuotes(usize),
/// Engine error that occurred due to a known limitation.
#[error(transparent)]
NotSupported(#[from] crate::error::UnsupportedFeatureError),
}
/// Errors in internal depth tracking of execution engines.
#[derive(Error, Debug)]
pub enum DepthError {
/// The engine's maximum depth limit was exceeded.
/// The inner [`usize`] indicates that limit.
#[error("Maximum depth of {0} exceeded.")]
AboveLimit(usize),
/// The document has unmatched closing characters
/// and is malformed.
#[error("Depth fell below zero.")]
BelowZero,
}