mysql_connector/error/
mod.rs

1mod parse;
2mod protocol;
3
4use {
5    crate::{connection::types::AuthPlugin, packets::ErrPacket},
6    std::io,
7};
8
9pub use {
10    parse::{InvalidFlags, ParseError},
11    protocol::{ProtocolError, SerializeError},
12};
13
14#[derive(Debug)]
15pub struct AuthPluginMismatch {
16    pub current: AuthPlugin,
17    pub requested: AuthPlugin,
18}
19
20#[derive(Debug)]
21pub enum RuntimeError {
22    ParameterCountMismatch,
23    InsecureAuth,
24    AuthPluginMismatch(AuthPluginMismatch),
25}
26
27impl RuntimeError {
28    pub fn auth_plugin_mismatch(current: AuthPlugin, requested: AuthPlugin) -> Self {
29        Self::AuthPluginMismatch(AuthPluginMismatch { current, requested })
30    }
31}
32
33#[derive(Debug)]
34pub enum Error {
35    Server(ErrPacket),
36    Protocol(ProtocolError),
37    Runtime(RuntimeError),
38}
39
40impl Error {
41    pub fn io_invalid_data<T>(err: T) -> Self
42    where
43        T: std::error::Error + Send + Sync + 'static,
44    {
45        Self::Protocol(ProtocolError::Io(io::Error::new(
46            io::ErrorKind::InvalidData,
47            err,
48        )))
49    }
50}
51
52impl From<ErrPacket> for Error {
53    fn from(value: ErrPacket) -> Self {
54        Self::Server(value)
55    }
56}
57
58impl From<ProtocolError> for Error {
59    fn from(value: ProtocolError) -> Self {
60        Self::Protocol(value)
61    }
62}
63
64impl From<RuntimeError> for Error {
65    fn from(value: RuntimeError) -> Self {
66        Self::Runtime(value)
67    }
68}