typed_clickhouse/
error.rs1use std::{error::Error as StdError, fmt, result, str::Utf8Error};
2
3use serde::{de, ser};
4
5pub type Result<T, E = Error> = result::Result<T, E>;
6
7#[derive(Debug, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10 #[error("invalid params: {0}")]
11 InvalidParams(#[source] Box<dyn StdError + Send>),
12 #[error("network error: {0}")]
13 Network(#[source] Box<dyn StdError + Send>),
14 #[error("sequences must have a knowable size ahead of time")]
15 SequenceMustHaveLength,
16 #[error("`deserialize_any` is not supported")]
17 DeserializeAnyNotSupported,
18 #[error("not enough data. Probably a row type mismatches a database schema")]
19 NotEnoughData,
20 #[error("string is not valid utf8")]
21 InvalidUtf8Encoding(#[from] Utf8Error),
22 #[error("tag for enum is not valid")]
23 InvalidTagEncoding(usize),
24 #[error("a custom error message from serde: {0}")]
25 Custom(String),
26 #[error("bad response: {0}")]
27 BadResponse(String),
28}
29
30impl From<hyper::Error> for Error {
31 fn from(error: hyper::Error) -> Self {
32 Self::Network(Box::new(error))
33 }
34}
35
36impl ser::Error for Error {
37 fn custom<T: fmt::Display>(msg: T) -> Self {
38 Self::Custom(msg.to_string())
39 }
40}
41
42impl de::Error for Error {
43 fn custom<T: fmt::Display>(msg: T) -> Self {
44 Self::Custom(msg.to_string())
45 }
46}