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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use std::fmt::{Debug, Display};
use std::io;
use std::result;
use std::str::Utf8Error;
use std::string::FromUtf8Error;
use thiserror::Error as ThisError;
use uuid::Error as UuidError;
use crate::compression::CompressionError;
use crate::frame::frame_error::ErrorBody;
pub type Result<T> = result::Result<T, Error>;
#[derive(Debug, ThisError)]
pub enum Error {
#[error("IO error: {0}")]
Io(#[from] io::Error),
#[error("Uuid parse error: {0}")]
UuidParse(#[from] UuidError),
#[error("General error: {0}")]
General(String),
#[error("FromUtf8 error: {0}")]
FromUtf8(#[from] FromUtf8Error),
#[error("Utf8 error: {0}")]
Utf8(#[from] Utf8Error),
#[error("Compressor error: {0}")]
Compression(#[from] CompressionError),
#[error("Server error: {0:?}")]
Server(ErrorBody),
#[error("Timeout: {0}")]
Timeout(String),
}
pub fn column_is_empty_err<T: Display>(column_name: T) -> Error {
Error::General(format!("Column or Udt property '{}' is empty", column_name))
}
impl From<ErrorBody> for Error {
fn from(err: ErrorBody) -> Error {
Error::Server(err)
}
}
impl From<String> for Error {
fn from(err: String) -> Error {
Error::General(err)
}
}
impl From<&str> for Error {
fn from(err: &str) -> Error {
Error::General(err.to_string())
}
}