Skip to content

Commit 6c55602

Browse files
committed
fixup! editoast: derive: introduce Model error management and update trait Delete
Signed-off-by: Leo Valais <[email protected]>
1 parent e4ef19c commit 6c55602

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

editoast/editoast_models/src/model.rs

+9-17
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,9 @@ fn try_parse_unique_violation(
3737
value: captures.get(2).unwrap().as_str().to_owned(),
3838
})
3939
} else {
40-
tracing::error!(
41-
?RE,
42-
error = e.message(),
43-
details = e.details(),
44-
"failed to parse PostgreSQL details message"
45-
);
4640
None
4741
}
4842
} else {
49-
tracing::error!(
50-
?RE,
51-
error = e.message(),
52-
"failed to parse PostgreSQL error message"
53-
);
5443
None
5544
}
5645
}
@@ -67,11 +56,6 @@ fn try_parse_check_violation(e: &Box<dyn DatabaseErrorInformation + Send + Sync>
6756
.to_owned(),
6857
})
6958
} else {
70-
tracing::error!(
71-
?RE,
72-
error = e.message(),
73-
"failed to parse PostgreSQL error message"
74-
);
7559
None
7660
}
7761
}
@@ -80,14 +64,22 @@ impl From<diesel::result::Error> for Error {
8064
fn from(e: diesel::result::Error) -> Self {
8165
match &e {
8266
diesel::result::Error::DatabaseError(DatabaseErrorKind::UniqueViolation, inner) => {
83-
try_parse_unique_violation(inner).unwrap_or_else(|| {
67+
try_parse_unique_violation(inner).unwrap_or_else(move || {
8468
// falling back to the generic error — since it's still semantically correct, logging the error is enough
69+
tracing::error!(
70+
error = %e,
71+
"failed to parse PostgreSQL details message"
72+
);
8573
Self::DatabaseError(e)
8674
})
8775
}
8876
diesel::result::Error::DatabaseError(DatabaseErrorKind::CheckViolation, inner) => {
8977
try_parse_check_violation(inner).unwrap_or_else(|| {
9078
// falling back to the generic error — since it's still semantically correct, logging the error is enough
79+
tracing::error!(
80+
error = %e,
81+
"failed to parse PostgreSQL details message"
82+
);
9183
Self::DatabaseError(e)
9284
})
9385
}

0 commit comments

Comments
 (0)