Skip to content

Commit

Permalink
Expose more error codes for PG
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Sep 30, 2024
1 parent ce6fa0b commit c5ef582
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions diesel/src/pg/connection/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ impl PgResult {
DatabaseErrorKind::NotNullViolation
}
Some(error_codes::CHECK_VIOLATION) => DatabaseErrorKind::CheckViolation,
Some(error_codes::RESTRICT_VIOLATION) => {
DatabaseErrorKind::RestrictViolation
}
Some(error_codes::EXCLUSION_VIOLATION) => {
DatabaseErrorKind::ExclusionViolation
}
Some(error_codes::CONNECTION_EXCEPTION)
| Some(error_codes::CONNECTION_FAILURE)
| Some(error_codes::SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION)
Expand Down Expand Up @@ -269,10 +275,12 @@ mod error_codes {
pub(in crate::pg::connection) const SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION: &str = "08001";
pub(in crate::pg::connection) const SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION: &str =
"08004";
pub(in crate::pg::connection) const RESTRICT_VIOLATION: &str = "23501";
pub(in crate::pg::connection) const NOT_NULL_VIOLATION: &str = "23502";
pub(in crate::pg::connection) const FOREIGN_KEY_VIOLATION: &str = "23503";
pub(in crate::pg::connection) const UNIQUE_VIOLATION: &str = "23505";
pub(in crate::pg::connection) const CHECK_VIOLATION: &str = "23514";
pub(in crate::pg::connection) const EXCLUSION_VIOLATION: &str = "23P01";
pub(in crate::pg::connection) const READ_ONLY_TRANSACTION: &str = "25006";
pub(in crate::pg::connection) const SERIALIZATION_FAILURE: &str = "40001";
}
6 changes: 6 additions & 0 deletions diesel/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,18 @@ pub enum DatabaseErrorKind {
/// to lock the rows.
ReadOnlyTransaction,

/// A restrict constraint was violated.
RestrictViolation,

/// A not null constraint was violated.
NotNullViolation,

/// A check constraint was violated.
CheckViolation,

/// An exclusion constraint was violated.
ExclusionViolation,

/// The connection to the server was unexpectedly closed.
///
/// This error is only detected for PostgreSQL and is emitted on a best-effort basis
Expand Down

0 comments on commit c5ef582

Please sign in to comment.