Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose error code for PG backend #4290

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
jrandolf marked this conversation as resolved.
Show resolved Hide resolved
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
Loading