Skip to content

Commit b0727b3

Browse files
committed
Error::UniqueViolation now provides a constraint instead of the full error
This is breaking
1 parent e590a54 commit b0727b3

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chuchi-postgres/src/connection.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ use crate::try2;
3232
#[derive(Debug, thiserror::Error)]
3333
#[non_exhaustive]
3434
pub enum Error {
35-
#[error("Unique violation {0}")]
36-
UniqueViolation(PgError),
35+
#[error("Unique violation {constraint:?}")]
36+
#[non_exhaustive]
37+
UniqueViolation { constraint: Option<String> },
3738

3839
#[error("Expected one row")]
3940
ExpectedOneRow,
@@ -50,12 +51,14 @@ pub enum Error {
5051

5152
impl From<PgError> for Error {
5253
fn from(e: PgError) -> Self {
53-
let Some(state) = e.code() else {
54+
let Some(db_error) = e.as_db_error() else {
5455
return Self::Other(e);
5556
};
5657

57-
match state {
58-
&SqlState::UNIQUE_VIOLATION => Self::UniqueViolation(e),
58+
match db_error.code() {
59+
&SqlState::UNIQUE_VIOLATION => Self::UniqueViolation {
60+
constraint: db_error.constraint().map(Into::into),
61+
},
5962
state => {
6063
error!("db error with state {:?}", state);
6164
Self::Other(e)

0 commit comments

Comments
 (0)