Skip to main content

PgServerError

Struct PgServerError 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§severity: String

Severity: ERROR, FATAL, PANIC, WARNING, NOTICE, DEBUG, INFO, LOG.

§severity_v: Option<String>

Localized severity (PostgreSQL ≥ 9.6).

§code: String

SQLSTATE error code (e.g., "23505" for unique violation).

§message: String

Primary 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

Source

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.

Source

pub fn from_error_body(body: &ErrorResponseBody) -> Result<Self, Error>

Parse a PgServerError from an ErrorResponseBody (wire message).

Source

pub fn from_notice_body(body: &NoticeResponseBody) -> Result<Self, Error>

Parse a PgServerError from a NoticeResponseBody (wire message).

Source

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.

Source

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.

Source

pub fn is_integrity_constraint_violation(&self) -> bool

Integrity constraint violation (SQLSTATE class 23).

Source

pub fn is_unique_violation(&self) -> bool

Unique constraint violation (23505).

Source

pub fn is_foreign_key_violation(&self) -> bool

Foreign key constraint violation (23503).

Source

pub fn is_not_null_violation(&self) -> bool

NOT NULL constraint violation (23502).

Source

pub fn is_check_violation(&self) -> bool

Check constraint violation (23514).

Source

pub fn is_exclusion_violation(&self) -> bool

Exclusion constraint violation (23P01).

Source

pub fn is_syntax_error(&self) -> bool

Syntax error or access violation (SQLSTATE class 42).

Source

pub fn is_insufficient_privilege(&self) -> bool

Insufficient privilege (42501).

Source

pub fn is_undefined_table(&self) -> bool

Undefined table (42P01).

Source

pub fn is_undefined_column(&self) -> bool

Undefined column (42703).

Source

pub fn is_serialization_failure(&self) -> bool

Serialization failure (40001).

Source

pub fn is_deadlock_detected(&self) -> bool

Deadlock detected (40P01).

Source

pub fn is_connection_exception(&self) -> bool

Connection exception (SQLSTATE class 08).

Source

pub fn is_connection_does_not_exist(&self) -> bool

Connection does not exist (08003).

Source

pub fn is_connection_failure(&self) -> bool

Connection failure (08006).

Source

pub fn is_sqlclient_unable_to_establish_sqlconnection(&self) -> bool

SQL client unable to establish SQL connection (08001).

Source

pub fn is_query_canceled(&self) -> bool

Query canceled (57014).

Source

pub fn is_admin_shutdown(&self) -> bool

Admin shutdown (57P01).

Source

pub fn is_crash_shutdown(&self) -> bool

Crash shutdown (57P02).

Source

pub fn is_cannot_connect_now(&self) -> bool

Cannot connect now (57P03).

Source

pub fn is_database_dropped(&self) -> bool

Database dropped (57P04).

Source

pub fn is_idle_session_timeout(&self) -> bool

Idle session timeout (57P05).

Source

pub fn is_fatal(&self) -> bool

Returns true if the error severity is FATAL or PANIC.

Source

pub fn is_warning_or_less(&self) -> bool

Returns true if the error severity is WARNING or lower (NOTICE, DEBUG, INFO, LOG).

Source

pub fn schema(&self) -> Option<&str>

Returns the schema name, if available.

Source

pub fn table(&self) -> Option<&str>

Returns the table name, if available.

Source

pub fn column(&self) -> Option<&str>

Returns the column name, if available.

Source

pub fn constraint(&self) -> Option<&str>

Returns the constraint name, if available.

Source

pub fn detail(&self) -> Option<&str>

Returns the detail, if available.

Source

pub fn hint(&self) -> Option<&str>

Returns the hint, if available.

Source

pub fn position(&self) -> Option<u32>

Returns the error position in the query, if available.

Trait Implementations§

Source§

impl Clone for PgServerError

Source§

fn clone(&self) -> PgServerError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PgServerError

Source§

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

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

impl Default for PgServerError

Source§

fn default() -> PgServerError

Returns the “default value” for a type. Read more
Source§

impl Display for PgServerError

Source§

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

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

impl Error for PgServerError

1.30.0 · Source§

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

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

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

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

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

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<PgServerError> for PgError

Source§

fn from(e: PgServerError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

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
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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