Error

Enum Error 

Source
pub enum Error {
Show 20 variants Connection(String), ConnectionClosed, Authentication(AuthError), Tls(String), Protocol(String), Codec(CodecError), Type(TypeError), Query(String), Server { number: i32, class: u8, state: u8, message: String, server: Option<String>, procedure: Option<String>, line: u32, }, Transaction(String), Config(String), ConnectTimeout, TlsTimeout, ConnectionTimeout, CommandTimeout, Routing { host: String, port: u16, }, TooManyRedirects { max: u8, }, Io(Arc<Error>), InvalidIdentifier(String), PoolExhausted,
}
Expand description

Errors that can occur during client operations.

Variants§

§

Connection(String)

Connection failed.

§

ConnectionClosed

Connection closed unexpectedly.

§

Authentication(AuthError)

Authentication failed.

§

Tls(String)

TLS error (string for flexibility in connection code).

§

Protocol(String)

Protocol error (string for flexibility in connection code).

§

Codec(CodecError)

Codec error.

§

Type(TypeError)

Type conversion error.

§

Query(String)

Query execution error.

§

Server

Server returned an error.

Fields

§number: i32

Error number.

§class: u8

Error class/severity (0-25).

§state: u8

Error state.

§message: String

Error message.

§server: Option<String>

Server name where error occurred.

§procedure: Option<String>

Stored procedure name (if applicable).

§line: u32

Line number in the SQL batch or procedure.

§

Transaction(String)

Transaction error.

§

Config(String)

Configuration error.

§

ConnectTimeout

TCP connection timeout occurred.

§

TlsTimeout

TLS handshake timeout occurred.

§

ConnectionTimeout

Connection timeout occurred (alias for backwards compatibility).

§

CommandTimeout

Command execution timeout occurred.

§

Routing

Connection routing required (Azure SQL).

Fields

§host: String

Target host.

§port: u16

Target port.

§

TooManyRedirects

Too many redirects during connection.

Fields

§max: u8

Maximum redirects allowed.

§

Io(Arc<Error>)

IO error (wrapped in Arc for Clone support).

§

InvalidIdentifier(String)

Invalid identifier (potential SQL injection attempt).

§

PoolExhausted

Connection pool exhausted.

Implementations§

Source§

impl Error

Source

pub fn is_transient(&self) -> bool

Check if this error is transient and may succeed on retry.

Transient errors include timeouts, connection issues, and certain server errors that may resolve themselves.

Per ADR-009, the following server error codes are considered transient:

  • 1205: Deadlock victim
  • -2: Timeout
  • 10928, 10929: Resource limit (Azure)
  • 40197: Service error (Azure)
  • 40501: Service busy (Azure)
  • 40613: Database unavailable (Azure)
  • 49918, 49919, 49920: Cannot process request (Azure)
  • 4060: Cannot open database (may be transient during failover)
  • 18456: Login failed (may be transient in Azure during failover)
Source

pub fn is_transient_server_error(number: i32) -> bool

Check if a server error number is transient (may succeed on retry).

This follows the error codes specified in ADR-009.

Source

pub fn is_terminal(&self) -> bool

Check if this is a terminal error that will never succeed on retry.

Terminal errors include syntax errors, constraint violations, and other errors that indicate programmer error or data issues.

Per ADR-009, the following server error codes are terminal:

  • 102: Syntax error
  • 207: Invalid column
  • 208: Invalid object
  • 547: Constraint violation
  • 2627: Unique constraint violation
  • 2601: Duplicate key
Source

pub fn is_terminal_server_error(number: i32) -> bool

Check if a server error number is terminal (will never succeed on retry).

This follows the error codes specified in ADR-009.

Source

pub fn is_protocol_error(&self) -> bool

Check if this error indicates a protocol/driver bug.

Protocol errors typically indicate a bug in the driver implementation rather than a user error or server issue.

Source

pub fn is_server_error(&self, number: i32) -> bool

Check if this is a server error with a specific number.

Source

pub fn class(&self) -> Option<u8>

Get the error class/severity if this is a server error.

SQL Server error classes range from 0-25:

  • 0-10: Informational
  • 11-16: User errors
  • 17-19: Resource/hardware errors
  • 20-25: System errors (connection terminating)
Source

pub fn severity(&self) -> Option<u8>

Alias for class() - returns error severity.

Trait Implementations§

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<AuthError> for Error

Source§

fn from(source: AuthError) -> Self

Converts to this type from the input type.
Source§

impl From<CodecError> for Error

Source§

fn from(source: CodecError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ProtocolError> for Error

Source§

fn from(e: ProtocolError) -> Self

Converts to this type from the input type.
Source§

impl From<TlsError> for Error

Source§

fn from(e: TlsError) -> Self

Converts to this type from the input type.
Source§

impl From<TypeError> for Error

Source§

fn from(source: TypeError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Error

§

impl !RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl !UnwindSafe for Error

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more