#![feature(backtrace)]
#![feature(type_ascription)]
mod decoding;
mod encoding;
pub mod buffer;
pub mod extended;
pub mod pg_type;
pub mod protocol;
pub use buffer::*;
pub use decoding::*;
pub use encoding::*;
pub use extended::*;
pub use pg_type::*;
use std::backtrace::Backtrace;
#[derive(thiserror::Error, Debug)]
pub enum ProtocolError {
#[error("IO Error: {}", .source)]
IO {
#[from]
source: std::io::Error,
backtrace: Backtrace,
},
#[error("Error: {}", .source.message)]
ErrorResponse {
#[from]
source: protocol::ErrorResponse,
backtrace: Backtrace,
},
}
impl ProtocolError {
pub fn backtrace(&self) -> Option<&Backtrace> {
match &self {
ProtocolError::IO { backtrace, .. } => Some(backtrace),
ProtocolError::ErrorResponse { backtrace, .. } => Some(backtrace),
}
}
pub fn to_error_response(self) -> protocol::ErrorResponse {
match self {
ProtocolError::IO { source, .. } => protocol::ErrorResponse::error(
protocol::ErrorCode::InternalError,
source.to_string(),
),
ProtocolError::ErrorResponse { source, .. } => source,
}
}
}