#[non_exhaustive]pub struct PgServerError {Show 18 fields
pub severity: String,
pub severity_v: Option<String>,
pub code: String,
pub message: String,
pub detail: Option<String>,
pub hint: Option<String>,
pub position: Option<u32>,
pub internal_position: Option<u32>,
pub internal_query: Option<String>,
pub where_: Option<String>,
pub schema: Option<String>,
pub table: Option<String>,
pub column: Option<String>,
pub data_type: Option<String>,
pub constraint: Option<String>,
pub file: Option<String>,
pub line: Option<u32>,
pub routine: Option<String>,
}Expand description
A structured error returned by the PostgreSQL server.
Every field corresponds to a field in the PostgreSQL ErrorResponse or
NoticeResponse message format. Only severity, code, and message
are always present; all other fields are Option.
§SQLSTATE codes
The code field contains the 5-character SQLSTATE error code defined by
the SQL standard and extended by PostgreSQL. See sqlstate
for constants and helper methods.
§Example
match err {
PgError::Server(e) => {
if e.is_unique_violation() {
println!("duplicate key: {}", e.constraint().unwrap_or_default());
}
}
_ => {}
}Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.severity: StringSeverity: ERROR, FATAL, PANIC, WARNING, NOTICE, DEBUG, INFO, LOG.
severity_v: Option<String>Localized severity (PostgreSQL ≥ 9.6).
code: StringSQLSTATE error code (e.g., "23505" for unique violation).
message: StringPrimary error message.
detail: Option<String>Optional detail providing additional context.
hint: Option<String>Optional suggestion for resolving the error.
position: Option<u32>Error position in the query string (1-based character offset).
internal_position: Option<u32>Internal position (position within internally-generated query).
internal_query: Option<String>Internal query (the internally-generated command that led to the error).
where_: Option<String>Call-stack context (e.g., in PL/pgSQL functions).
schema: Option<String>Schema name (if applicable).
table: Option<String>Table name (if applicable).
column: Option<String>Column name (if applicable).
data_type: Option<String>Data type name (if applicable).
constraint: Option<String>Constraint name (if applicable).
file: Option<String>Source file in the PostgreSQL server code.
line: Option<u32>Source line number in the PostgreSQL server code.
routine: Option<String>Source routine in the PostgreSQL server code.
Implementations§
Source§impl PgServerError
impl PgServerError
Sourcepub fn from_fields(fields: Vec<(u8, String)>) -> Self
pub fn from_fields(fields: Vec<(u8, String)>) -> Self
Parse a PgServerError from the raw (type_byte, value) field pairs
of a PostgreSQL ErrorResponse or NoticeResponse message.
Sourcepub fn from_error_body(body: &ErrorResponseBody) -> Result<Self, Error>
pub fn from_error_body(body: &ErrorResponseBody) -> Result<Self, Error>
Parse a PgServerError from an ErrorResponseBody (wire message).
Sourcepub fn from_notice_body(body: &NoticeResponseBody) -> Result<Self, Error>
pub fn from_notice_body(body: &NoticeResponseBody) -> Result<Self, Error>
Parse a PgServerError from a NoticeResponseBody (wire message).
Sourcepub fn code(&self) -> &str
pub fn code(&self) -> &str
Returns the SQLSTATE error code (e.g., "23505" for unique violation).
This is a convenience accessor equivalent to accessing the code field.
Sourcepub fn is_class(&self, class: &str) -> bool
pub fn is_class(&self, class: &str) -> bool
Check if the SQLSTATE code belongs to the given 2-character class.
SQLSTATE codes are 5 characters. The first two characters identify
the error class. For example, class "23" is integrity constraint
violations, class "42" is syntax error or access violation.
Sourcepub fn is_integrity_constraint_violation(&self) -> bool
pub fn is_integrity_constraint_violation(&self) -> bool
Integrity constraint violation (SQLSTATE class 23).
Sourcepub fn is_unique_violation(&self) -> bool
pub fn is_unique_violation(&self) -> bool
Unique constraint violation (23505).
Sourcepub fn is_foreign_key_violation(&self) -> bool
pub fn is_foreign_key_violation(&self) -> bool
Foreign key constraint violation (23503).
Sourcepub fn is_not_null_violation(&self) -> bool
pub fn is_not_null_violation(&self) -> bool
NOT NULL constraint violation (23502).
Sourcepub fn is_check_violation(&self) -> bool
pub fn is_check_violation(&self) -> bool
Check constraint violation (23514).
Sourcepub fn is_exclusion_violation(&self) -> bool
pub fn is_exclusion_violation(&self) -> bool
Exclusion constraint violation (23P01).
Sourcepub fn is_syntax_error(&self) -> bool
pub fn is_syntax_error(&self) -> bool
Syntax error or access violation (SQLSTATE class 42).
Sourcepub fn is_insufficient_privilege(&self) -> bool
pub fn is_insufficient_privilege(&self) -> bool
Insufficient privilege (42501).
Sourcepub fn is_undefined_table(&self) -> bool
pub fn is_undefined_table(&self) -> bool
Undefined table (42P01).
Sourcepub fn is_undefined_column(&self) -> bool
pub fn is_undefined_column(&self) -> bool
Undefined column (42703).
Sourcepub fn is_serialization_failure(&self) -> bool
pub fn is_serialization_failure(&self) -> bool
Serialization failure (40001).
Sourcepub fn is_deadlock_detected(&self) -> bool
pub fn is_deadlock_detected(&self) -> bool
Deadlock detected (40P01).
Sourcepub fn is_connection_exception(&self) -> bool
pub fn is_connection_exception(&self) -> bool
Connection exception (SQLSTATE class 08).
Sourcepub fn is_connection_does_not_exist(&self) -> bool
pub fn is_connection_does_not_exist(&self) -> bool
Connection does not exist (08003).
Sourcepub fn is_connection_failure(&self) -> bool
pub fn is_connection_failure(&self) -> bool
Connection failure (08006).
Sourcepub fn is_sqlclient_unable_to_establish_sqlconnection(&self) -> bool
pub fn is_sqlclient_unable_to_establish_sqlconnection(&self) -> bool
SQL client unable to establish SQL connection (08001).
Sourcepub fn is_query_canceled(&self) -> bool
pub fn is_query_canceled(&self) -> bool
Query canceled (57014).
Sourcepub fn is_admin_shutdown(&self) -> bool
pub fn is_admin_shutdown(&self) -> bool
Admin shutdown (57P01).
Sourcepub fn is_crash_shutdown(&self) -> bool
pub fn is_crash_shutdown(&self) -> bool
Crash shutdown (57P02).
Sourcepub fn is_cannot_connect_now(&self) -> bool
pub fn is_cannot_connect_now(&self) -> bool
Cannot connect now (57P03).
Sourcepub fn is_database_dropped(&self) -> bool
pub fn is_database_dropped(&self) -> bool
Database dropped (57P04).
Sourcepub fn is_idle_session_timeout(&self) -> bool
pub fn is_idle_session_timeout(&self) -> bool
Idle session timeout (57P05).
Sourcepub fn is_warning_or_less(&self) -> bool
pub fn is_warning_or_less(&self) -> bool
Returns true if the error severity is WARNING or lower
(NOTICE, DEBUG, INFO, LOG).
Sourcepub fn constraint(&self) -> Option<&str>
pub fn constraint(&self) -> Option<&str>
Returns the constraint name, if available.
Trait Implementations§
Source§impl Clone for PgServerError
impl Clone for PgServerError
Source§fn clone(&self) -> PgServerError
fn clone(&self) -> PgServerError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PgServerError
impl Debug for PgServerError
Source§impl Default for PgServerError
impl Default for PgServerError
Source§fn default() -> PgServerError
fn default() -> PgServerError
Source§impl Display for PgServerError
impl Display for PgServerError
Source§impl Error for PgServerError
impl Error for PgServerError
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()