#[non_exhaustive]pub enum Error {
Show 23 variants
Connection(String),
ConnectionClosed,
Authentication(AuthError),
Tls(TlsError),
ProtocolError(ProtocolError),
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,
},
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),
PoolExhausted,
Cancel(String),
Cancelled,
BrowserResolution {
instance: String,
reason: 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.
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.
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).
PoolExhausted
Connection pool exhausted.
Cancel(String)
Query cancellation error.
Cancelled
Query was cancelled by user request.
BrowserResolution
SQL Browser service instance resolution failed.
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()