summary refs log tree commit diff stats
path: root/src/errors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/errors.rs')
-rw-r--r--src/errors.rs34
1 files changed, 34 insertions, 0 deletions
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<T>(msg: T) -> Self where T: std::fmt::Display {
+        Self::Serde(serde::de::value::Error::custom(msg))
+    }
+}