forked from transact-rs/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.rs
More file actions
61 lines (49 loc) · 1.83 KB
/
Copy pathclient.rs
File metadata and controls
61 lines (49 loc) · 1.83 KB
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
use std::error::Error as StdError;
use std::fmt::{self, Display, Formatter};
use std::str::Utf8Error;
use sqlx_core::{ClientError, Error};
#[derive(Debug)]
#[non_exhaustive]
pub enum PgClientError {
// attempting to interpret data from postgres as UTF-8, when it should
// be UTF-8, but for some reason (data corruption?) it is not
NotUtf8(Utf8Error),
UnknownAuthMethod(u32),
UnknownMessageType(u8),
UnknownTransactionStatus(u8),
UnknownValueFormat(i16),
UnknownNoticeSeverity(Box<str>),
UnexpectedMessageType { ty: u8, context: &'static str },
}
impl Display for PgClientError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::NotUtf8(source) => write!(f, "unexpected invalid utf-8: {}", source),
Self::UnknownAuthMethod(method) => {
write!(f, "unknown authentication method: {}", method)
}
Self::UnknownTransactionStatus(status) => {
write!(f, "in ReadyForQuery, unknown transaction status: {}", status)
}
Self::UnknownNoticeSeverity(severity) => {
write!(f, "unknown notice severity: {}", severity)
}
Self::UnknownValueFormat(format) => {
write!(f, "unknown value format: {}", format)
}
Self::UnknownMessageType(ty) => {
write!(f, "unknown protocol message type: '{}' ({})", *ty as char, *ty)
}
Self::UnexpectedMessageType { ty, context } => {
write!(f, "unexpected message {:?} '{}' while {}", ty, (*ty as u8 as char), context)
}
}
}
}
impl StdError for PgClientError {}
impl ClientError for PgClientError {}
impl From<PgClientError> for Error {
fn from(err: PgClientError) -> Self {
Self::client(err)
}
}