mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-29 21:00:54 +00:00
feat(core): add Error::Client and ClientError to represent a general client error, replacing Error::Protocol
This commit is contained in:
parent
2b8ca88b87
commit
6d869bef7e
@ -7,8 +7,10 @@ use either::Either;
|
||||
use crate::decode::Error as DecodeError;
|
||||
use crate::encode::Error as EncodeError;
|
||||
|
||||
mod client;
|
||||
mod database;
|
||||
|
||||
pub use client::ClientError;
|
||||
pub use database::DatabaseError;
|
||||
|
||||
use crate::Column;
|
||||
@ -25,9 +27,16 @@ pub enum Error {
|
||||
/// to be parsed.
|
||||
ConnectOptions { message: Cow<'static, str>, source: Option<Box<dyn StdError + Send + Sync>> },
|
||||
|
||||
/// The database returned an error.
|
||||
/// An error that was returned from the database, normally from the
|
||||
/// execution of a SQL command.
|
||||
///
|
||||
Database(Box<dyn DatabaseError>),
|
||||
|
||||
/// An error was identified on the client from the result of interacting
|
||||
/// with the database.
|
||||
///
|
||||
Client(Box<dyn ClientError>),
|
||||
|
||||
/// An IO error returned while reading or writing a socket attached
|
||||
/// to the database server.
|
||||
///
|
||||
@ -92,6 +101,16 @@ impl Error {
|
||||
Self::ConnectOptions { message: message.into(), source: None }
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn client(err: impl ClientError) -> Self {
|
||||
Self::Client(Box::new(err))
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn database(err: impl DatabaseError) -> Self {
|
||||
Self::Database(Box::new(err))
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn column_decode(column: &impl Column, source: DecodeError) -> Self {
|
||||
crate::Error::ColumnDecode {
|
||||
@ -109,6 +128,8 @@ impl Display for Error {
|
||||
|
||||
Self::Database(source) => write!(f, "{}", source),
|
||||
|
||||
Self::Client(source) => write!(f, "{}", source),
|
||||
|
||||
Self::ConnectOptions { message, source: None } => {
|
||||
write!(f, "{}", message)
|
||||
}
|
||||
|
||||
11
sqlx-core/src/error/client.rs
Normal file
11
sqlx-core/src/error/client.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use std::error::Error as StdError;
|
||||
|
||||
/// Representing an error that was identified by the client as a result
|
||||
/// of interacting with the database.
|
||||
///
|
||||
/// This can be anything from receiving invalid UTF-8 from the database
|
||||
/// (where valid UTF-8 is expected) to being asked for interactive
|
||||
/// authentication (where none is supported).
|
||||
///
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
pub trait ClientError: 'static + StdError + Send + Sync {}
|
||||
@ -1,7 +1,6 @@
|
||||
use std::error::Error as StdError;
|
||||
|
||||
/// `DatabaseError` is a trait representing an error that was returned from
|
||||
/// the database.
|
||||
/// Representing an error that was returned from the database.
|
||||
///
|
||||
/// Provides abstract access to information returned from the database about
|
||||
/// the error.
|
||||
|
||||
@ -22,12 +22,12 @@
|
||||
mod acquire;
|
||||
pub mod arguments;
|
||||
mod close;
|
||||
mod describe;
|
||||
mod column;
|
||||
mod connect;
|
||||
mod connection;
|
||||
pub mod database;
|
||||
pub mod decode;
|
||||
mod describe;
|
||||
pub mod encode;
|
||||
mod error;
|
||||
mod execute;
|
||||
@ -65,8 +65,9 @@ pub use connect::Connect;
|
||||
pub use connection::Connection;
|
||||
pub use database::Database;
|
||||
pub use decode::Decode;
|
||||
pub use describe::Describe;
|
||||
pub use encode::Encode;
|
||||
pub use error::{DatabaseError, Error, Result};
|
||||
pub use error::{ClientError, DatabaseError, Error, Result};
|
||||
pub use execute::Execute;
|
||||
pub use executor::Executor;
|
||||
pub use from_row::FromRow;
|
||||
@ -86,4 +87,3 @@ pub use runtime::Runtime;
|
||||
#[cfg(feature = "tokio")]
|
||||
pub use runtime::Tokio;
|
||||
pub use type_info::TypeInfo;
|
||||
pub use describe::Describe;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user