welds_sqlx_mssql/
error.rs

1use crate::protocol::error::Error as ProtoError;
2use std::error::Error as StdError;
3use std::fmt::{self, Debug, Display, Formatter};
4
5pub(crate) use sqlx_core::error::*;
6
7/// An error returned from the MSSQL database.
8pub struct MssqlDatabaseError(pub(crate) ProtoError);
9
10impl Debug for MssqlDatabaseError {
11    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
12        f.debug_struct("MssqlDatabaseError")
13            .field("message", &self.0.message)
14            .field("number", &self.0.number)
15            .field("state", &self.0.state)
16            .field("class", &self.0.class)
17            .field("server", &self.0.server)
18            .field("procedure", &self.0.procedure)
19            .field("line", &self.0.line)
20            .finish()
21    }
22}
23
24impl Display for MssqlDatabaseError {
25    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
26        f.pad(self.message())
27    }
28}
29
30impl StdError for MssqlDatabaseError {}
31
32impl DatabaseError for MssqlDatabaseError {
33    #[inline]
34    fn message(&self) -> &str {
35        &self.0.message
36    }
37
38    #[doc(hidden)]
39    fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {
40        self
41    }
42
43    #[doc(hidden)]
44    fn as_error_mut(&mut self) -> &mut (dyn StdError + Send + Sync + 'static) {
45        self
46    }
47
48    #[doc(hidden)]
49    fn into_error(self: Box<Self>) -> Box<dyn StdError + Send + Sync + 'static> {
50        self
51    }
52
53    fn kind(&self) -> ErrorKind {
54        //    //error_codes::UNIQUE_VIOLATION => ErrorKind::UniqueViolation,
55        //    //error_codes::FOREIGN_KEY_VIOLATION => ErrorKind::ForeignKeyViolation,
56        //    //error_codes::NOT_NULL_VIOLATION => ErrorKind::NotNullViolation,
57        //    //error_codes::CHECK_VIOLATION => ErrorKind::CheckViolation,
58        //    //_ => ErrorKind::Other,
59        //}
60        //TODO: // report the correct KIND of error
61        ErrorKind::Other
62    }
63}