pub struct DbError {
pub severity: SmallString<8>,
pub code: SmallString<5>,
pub message: String,
pub detail: Option<String>,
pub hint: Option<String>,
pub position: Option<i32>,
pub constraint: Option<String>,
pub table: Option<String>,
pub column: Option<String>,
pub schema: Option<String>,
pub data_type: Option<String>,
}Expand description
A structured ErrorResponse / NoticeResponse from the server.
Fields§
§severity: SmallString<8>Localized severity (ERROR, FATAL, …).
Stored inline; only values longer than 8 bytes (unusual localizations) spill onto the heap.
code: SmallString<5>SQLSTATE code.
The wire protocol bounds this to five bytes, so it is always stored inline and decoding it never allocates.
message: StringPrimary human-readable message.
detail: Option<String>Optional detail.
hint: Option<String>Optional hint.
position: Option<i32>Optional 1-based character position in the query.
constraint: Option<String>Optional constraint name.
table: Option<String>Optional table name.
column: Option<String>Optional column name.
schema: Option<String>Optional schema name.
data_type: Option<String>Optional data type name.
Implementations§
Source§impl DbError
impl DbError
Sourcepub fn class(&self) -> &str
pub fn class(&self) -> &str
Returns the SQLSTATE class (the first two characters), e.g. 23 for
integrity constraint violations.
Returns "" when no code was reported. The code is server-supplied and
may contain arbitrary bytes, so a short or non-ASCII code is truncated
at a character boundary rather than panicking.
Sourcepub fn is_data_exception(&self) -> bool
pub fn is_data_exception(&self) -> bool
true for SQLSTATE class 22 (data exception).
Sourcepub fn is_integrity_violation(&self) -> bool
pub fn is_integrity_violation(&self) -> bool
true for SQLSTATE class 23 (integrity constraint violation).
Sourcepub fn is_unique_violation(&self) -> bool
pub fn is_unique_violation(&self) -> bool
true for 23505 (unique violation).
Sourcepub fn is_foreign_key_violation(&self) -> bool
pub fn is_foreign_key_violation(&self) -> bool
true for 23503 (foreign key violation).
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
true for 40P01 (deadlock detected) or 40001 (serialization failure),
both of which are safe to retry.
Trait Implementations§
Source§impl Error for DbError
impl Error for DbError
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()