use std::sync::Arc;
use thiserror::Error;
#[derive(Debug, Error, Clone)]
pub enum PgWireError {
#[error("io error: {0}")]
Io(Arc<std::io::Error>),
#[error("protocol error: {0}")]
Protocol(String),
#[error("server error: {0}")]
Server(String),
#[error("authentication error: {0}")]
Auth(String),
#[error("tls error: {0}")]
Tls(String),
#[error("task error: {0}")]
Task(String),
#[error("internal error: {0}")]
Internal(String),
}
impl PgWireError {
#[inline]
pub fn is_io(&self) -> bool {
matches!(self, PgWireError::Io(_))
}
#[inline]
pub fn is_server(&self) -> bool {
matches!(self, PgWireError::Server(_))
}
#[inline]
pub fn is_auth(&self) -> bool {
matches!(self, PgWireError::Auth(_))
}
#[inline]
pub fn is_tls(&self) -> bool {
matches!(self, PgWireError::Tls(_))
}
pub fn is_transient(&self) -> bool {
matches!(self, PgWireError::Io(_) | PgWireError::Task(_))
}
}
impl From<std::io::Error> for PgWireError {
fn from(err: std::io::Error) -> Self {
PgWireError::Io(Arc::new(err))
}
}
pub type Result<T> = std::result::Result<T, PgWireError>;