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
use std::{error::Error as StdError, fmt, result, str::Utf8Error}; use serde::{de, ser}; pub type Result<T, E = Error> = result::Result<T, E>; #[derive(Debug, thiserror::Error)] #[non_exhaustive] pub enum Error { #[error("invalid params: {0}")] InvalidParams(#[source] Box<dyn StdError + Send>), #[error("network error: {0}")] Network(#[source] Box<dyn StdError + Send>), #[error("sequences must have a knowable size ahead of time")] SequenceMustHaveLength, #[error("`deserialize_any` is not supported")] DeserializeAnyNotSupported, #[error("not enough data. Probably a row type mismatches a database schema")] NotEnoughData, #[error("string is not valid utf8")] InvalidUtf8Encoding(#[from] Utf8Error), #[error("tag for enum is not valid")] InvalidTagEncoding(usize), #[error("a custom error message from serde: {0}")] Custom(String), #[error("bad response: {0}")] BadResponse(String), } impl From<hyper::Error> for Error { fn from(error: hyper::Error) -> Self { Self::Network(Box::new(error)) } } impl ser::Error for Error { fn custom<T: fmt::Display>(msg: T) -> Self { Self::Custom(msg.to_string()) } } impl de::Error for Error { fn custom<T: fmt::Display>(msg: T) -> Self { Self::Custom(msg.to_string()) } }