#[non_exhaustive]pub enum Error {
Show 24 variants
Connection(String),
ConnectionClosed,
Authentication(AuthError),
Tls(TlsError),
ProtocolError(ProtocolError),
Protocol(String),
Codec(CodecError),
ResponseTooLarge {
size: usize,
limit: usize,
},
Type(TypeError),
Query(String),
Server {
number: i32,
class: u8,
state: u8,
message: String,
server: Option<String>,
procedure: Option<String>,
line: u32,
},
Config(String),
ConnectTimeout {
host: String,
port: u16,
},
TlsTimeout {
host: String,
port: u16,
},
LoginTimeout {
host: String,
port: u16,
},
CommandTimeout,
Routing {
host: String,
port: u16,
},
TooManyRedirects {
max: u8,
},
Io(SharedIoError),
InvalidIdentifier(String),
Cancel(String),
Cancelled,
BrowserResolution {
instance: String,
reason: String,
},
Encryption(String),
}Expand description
Errors that can occur during client operations.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Connection(String)
Connection failed.
ConnectionClosed
Connection closed unexpectedly.
Authentication(AuthError)
Authentication failed.
Tls(TlsError)
TLS error.
ProtocolError(ProtocolError)
Protocol error from the TDS layer (preserves the source error chain).
Protocol(String)
Protocol violation with a descriptive message.
Codec(CodecError)
Codec error.
ResponseTooLarge
Response exceeded Config::max_response_size.
The response was abandoned mid-stream, so the connection is no longer usable and is discarded by the pool. Paginate, narrow the SELECT, or raise the cap.
Type(TypeError)
Type conversion error.
Query(String)
Query execution error.
Server
Server returned an error.
Fields
Config(String)
Configuration error.
ConnectTimeout
TCP connection timeout occurred.
TlsTimeout
TLS handshake timeout occurred.
LoginTimeout
Login/authentication response timeout occurred.
CommandTimeout
Command execution timeout occurred.
The driver cancels the command via an Attention packet and drains the server’s acknowledgement, so the connection normally stays usable. If the server never acknowledges within a bounded wait (5 s, SqlClient parity), the connection is left mid-response and is discarded by the pool instead of being reused.
Routing
Connection routing required (Azure SQL).
TooManyRedirects
Too many redirects during connection.
Io(SharedIoError)
IO error (wrapped in Arc for Clone support).
InvalidIdentifier(String)
Invalid identifier (potential SQL injection attempt).
Cancel(String)
Query cancellation error.
Cancelled
Query was cancelled by user request.
BrowserResolution
SQL Browser service instance resolution failed.
Fields
Encryption(String)
Always Encrypted operation failed.
This error occurs during CEK decryption, column value decryption, or parameter encryption. Key material is never included in the error message.
Implementations§
Source§impl Error
impl Error
Sourcepub fn is_transient(&self) -> bool
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)
Sourcepub fn is_transient_server_error(number: i32) -> bool
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.
§Extending with custom error codes
Applications with domain-specific transient error codes can compose this method with their own logic:
use mssql_client::Error;
fn is_transient_for_my_app(err: &Error) -> bool {
// Check built-in transient codes first
if err.is_transient() {
return true;
}
// Add application-specific transient server errors
if let Error::Server { number, .. } = err {
matches!(number, 50001 | 50002) // custom app error codes
} else {
false
}
}Sourcepub fn is_terminal(&self) -> bool
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
Sourcepub fn is_terminal_server_error(number: i32) -> bool
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.
Sourcepub fn is_protocol_error(&self) -> bool
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. These are always terminal.
Sourcepub fn is_tls_error(&self) -> bool
pub fn is_tls_error(&self) -> bool
Check if this is a TLS/encryption error.
TLS errors indicate certificate, handshake, or encryption failures.
These are terminal — TLS timeouts are reported as Error::TlsTimeout instead.
Sourcepub fn is_authentication_error(&self) -> bool
pub fn is_authentication_error(&self) -> bool
Check if this is an authentication error.
Sourcepub fn is_config_error(&self) -> bool
pub fn is_config_error(&self) -> bool
Check if this is a configuration error.
Configuration errors are always terminal — they indicate invalid settings that cannot be resolved by retrying.
Sourcepub fn is_server_error(&self, number: i32) -> bool
pub fn is_server_error(&self, number: i32) -> bool
Check if this is a server error with a specific number.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
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()
Source§impl From<CodecError> for Error
impl From<CodecError> for Error
Source§fn from(e: CodecError) -> Self
fn from(e: CodecError) -> Self
Source§impl From<EncryptionError> for Error
Available on crate feature always-encrypted only.
impl From<EncryptionError> for Error
always-encrypted only.Source§fn from(e: EncryptionError) -> Self
fn from(e: EncryptionError) -> Self
Source§impl From<ProtocolError> for Error
impl From<ProtocolError> for Error
Source§fn from(source: ProtocolError) -> Self
fn from(source: ProtocolError) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for Error
impl !UnwindSafe for Error
impl Freeze for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin 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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.