From d849f5e301fa47cfd87df1e7f1ad0346ddf387f1 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sat, 8 Apr 2023 18:52:00 -0300 Subject: Initial success --- src/errors.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/errors.rs') diff --git a/src/errors.rs b/src/errors.rs index 914b70a..ea1e60d 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -56,3 +56,37 @@ pub enum MatchError { /// requirements. Unsatisfiable, } + +#[derive(Debug)] +#[non_exhaustive] +pub enum QueryError { + /// Returned if the deserialization recurses too deeply. + StackOverflow, + /// Returned if there's nothing to deserialize. + Empty, + /// The query is unsatisfiable. This happens if e.g. there are multiple + /// values in the query but only one value can fit into the request. + Unsatisfiable, + /// Wrapped Serde error. + Serde(serde::de::value::Error), +} + +impl std::fmt::Display for QueryError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::StackOverflow => write!(f, "stack overflow"), + Self::Empty => write!(f, "no results"), + Self::Unsatisfiable => write!(f, "unsatisfiable"), + Self::Serde(e) => e.fmt(f), + } + } +} + +impl std::error::Error for QueryError { +} + +impl serde::de::Error for QueryError { + fn custom(msg: T) -> Self where T: std::fmt::Display { + Self::Serde(serde::de::value::Error::custom(msg)) + } +} -- cgit 1.4.1