pub enum Error {
Connection {
message: String,
sqlstate: Option<String>,
},
Authentication(String),
Query {
message: String,
sqlstate: Option<String>,
detail: Option<String>,
hint: Option<String>,
},
Protocol(String),
Io(String),
Config(String),
Timeout(String),
Cancelled {
message: String,
sqlstate: Option<String>,
},
Closed {
message: String,
sqlstate: Option<String>,
},
Conversion(String),
FeatureNotSupported(String),
Other(String),
}Expand description
The error type for Hyper client operations.
Variants that can carry a server-supplied SQLSTATE expose it as a field, so callers match on it structurally rather than scraping the message. The remaining variants are single-string: whatever context exists is already rendered into that string by the constructor.
Deliberately not #[non_exhaustive]. That attribute buys
forward-compatibility for downstream matches, which this type has no
use for: it is internal, not re-exported, and hyperdb-api is its only
consumer and ships from this same workspace in lockstep. What it would
cost is the compile-time exhaustiveness check on
From<client::Error> for hyperdb_api::Error — the one place a new
variant must be given a public mapping. Better that adding a variant
breaks that build than silently degrades to Error::Internal.
Variants§
Connection
Connection failed.
Fields
Authentication(String)
Authentication failed.
Query
Query execution failed.
The one variant that carries the server’s full diagnostic
payload — DETAIL and HINT are surfaced verbatim by the public
hyperdb_api::Error::Server variant this maps to.
Fields
Protocol(String)
Invalid response from server.
Io(String)
I/O error.
Config(String)
Configuration error.
Timeout(String)
Operation timed out.
Cancelled
Operation was cancelled.
Fields
Closed
The connection was closed.
Fields
Conversion(String)
Type conversion error.
FeatureNotSupported(String)
Feature not supported by this connection type.
Other(String)
Other error.
Implementations§
Source§impl Error
impl Error
Sourcepub fn connection(message: impl Into<String>) -> Self
pub fn connection(message: impl Into<String>) -> Self
Creates a connection error with no SQLSTATE.
Sourcepub fn authentication(message: impl Into<String>) -> Self
pub fn authentication(message: impl Into<String>) -> Self
Creates an authentication error.
Sourcepub fn query(message: impl Into<String>) -> Self
pub fn query(message: impl Into<String>) -> Self
Creates a query error with no SQLSTATE, detail, or hint.
Sourcepub fn io(message: impl Into<String>) -> Self
pub fn io(message: impl Into<String>) -> Self
Creates an I/O error from a message.
Prefer Error::from_io when an io::Error is in hand.
Sourcepub fn cancelled(message: impl Into<String>) -> Self
pub fn cancelled(message: impl Into<String>) -> Self
Creates a cancellation error with no SQLSTATE.
Sourcepub fn closed(message: impl Into<String>) -> Self
pub fn closed(message: impl Into<String>) -> Self
Creates a closed-connection error with no SQLSTATE.
Sourcepub fn conversion(message: impl Into<String>) -> Self
pub fn conversion(message: impl Into<String>) -> Self
Creates a type-conversion error.
Sourcepub fn feature_not_supported(message: impl Into<String>) -> Self
pub fn feature_not_supported(message: impl Into<String>) -> Self
Creates a “feature not supported” error.
Used when an operation is not available on a particular connection type (e.g. write operations on gRPC connections).
Sourcepub fn from_io(err: Error) -> Self
pub fn from_io(err: Error) -> Self
Creates an I/O error from an io::Error.
Takes the error by value so it can be used point-free as
.map_err(Error::from_io).
Sourcepub fn db(severity: &str, code: &str, message: &str) -> Self
pub fn db(severity: &str, code: &str, message: &str) -> Self
Creates an error from a database error response.
Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
Returns the error message, without any DETAIL suffix that
Display would append.
Sourcepub fn sqlstate(&self) -> Option<&str>
pub fn sqlstate(&self) -> Option<&str>
Extracts the PostgreSQL SQLSTATE code from the error, if present.
SQLSTATE codes are 5-character codes that identify error conditions. See: https://www.postgresql.org/docs/current/errcodes-appendix.html
For Error::Query with no stored code, falls back to scraping the
trailing (CODE) that Hyper appends to wire error messages.
§Example
use hyperdb_api_core::client::Error;
let err = Error::db("ERROR", "42P04", "database already exists");
assert_eq!(err.sqlstate(), Some("42P04"));Trait Implementations§
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for Error
impl RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
impl UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request