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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
pub use crate::tds::codec::TokenError;
pub use std::io::ErrorKind as IoErrorKind;
use std::{borrow::Cow, convert::Infallible, io};
use thiserror::Error;
#[derive(Debug, Clone, Error)]
pub enum Error {
#[error("An error occured during the attempt of performing I/O: {}", message)]
Io {
kind: IoErrorKind,
message: String,
},
#[error("Protocol error: {}", _0)]
Protocol(Cow<'static, str>),
#[error("Encoding error: {}", _0)]
Encoding(Cow<'static, str>),
#[error("Conversion error: {}", _0)]
Conversion(Cow<'static, str>),
#[error("UTF-8 error")]
Utf8,
#[error("UTF-16 error")]
Utf16,
#[error("Error parsing an integer: {}", _0)]
ParseInt(std::num::ParseIntError),
#[error("Token error: {}", _0)]
Server(TokenError),
#[error("Error forming TLS connection: {}", _0)]
Tls(String),
#[cfg(any(all(unix, feature = "integrated-auth-gssapi"), doc))]
#[cfg_attr(
feature = "docs",
doc(cfg(all(unix, feature = "integrated-auth-gssapi")))
)]
#[error("GSSAPI Error: {}", _0)]
Gssapi(String),
#[error(
"Server requested a connection to an alternative address: `{}:{}`",
host,
port
)]
Routing {
host: String,
port: u16,
},
}
impl From<uuid::Error> for Error {
fn from(e: uuid::Error) -> Self {
Self::Conversion(format!("Error convertiong a Guid value {}", e).into())
}
}
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg_attr(
feature = "docs",
doc(cfg(any(target_os = "macos", target_os = "ios")))
)]
impl From<opentls::Error> for Error {
fn from(v: opentls::Error) -> Self {
Error::Tls(format!("{}", v))
}
}
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
#[cfg_attr(
feature = "docs",
doc(cfg(not(any(target_os = "macos", target_os = "ios"))))
)]
impl From<async_native_tls::Error> for Error {
fn from(v: async_native_tls::Error) -> Self {
Error::Tls(format!("{}", v))
}
}
impl From<Infallible> for Error {
fn from(_: Infallible) -> Self {
unreachable!()
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Error {
Self::Io {
kind: err.kind(),
message: format!("{}", err),
}
}
}
impl From<std::num::ParseIntError> for Error {
fn from(err: std::num::ParseIntError) -> Error {
Error::ParseInt(err)
}
}
impl From<std::str::Utf8Error> for Error {
fn from(_: std::str::Utf8Error) -> Error {
Error::Utf8
}
}
impl From<std::string::FromUtf8Error> for Error {
fn from(_err: std::string::FromUtf8Error) -> Error {
Error::Utf8
}
}
impl From<std::string::FromUtf16Error> for Error {
fn from(_err: std::string::FromUtf16Error) -> Error {
Error::Utf16
}
}
impl From<connection_string::Error> for Error {
fn from(err: connection_string::Error) -> Error {
let err = Cow::Owned(format!("{}", err));
Error::Conversion(err)
}
}
#[cfg(all(unix, feature = "integrated-auth-gssapi"))]
#[cfg_attr(
feature = "docs",
doc(cfg(all(unix, feature = "integrated-auth-gssapi")))
)]
impl From<libgssapi::error::Error> for Error {
fn from(err: libgssapi::error::Error) -> Error {
Error::Gssapi(format!("{}", err))
}
}