Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ce7ce31

Browse files
committedAug 1, 2020
Give a more helpful message on error
Before: ``` database error: ERROR: insert or update on table "owner_rels" violates foreign key constraint "owner_rels_cid_fkey" ``` After: ``` database error: ERROR: insert or update on table "owner_rels" violates foreign key constraint "owner_rels_cid_fkey" DETAIL: Key (cid)=(4) is not present in table "releases". ```
1 parent 286b9dc commit ce7ce31

File tree

1 file changed

+8
-1
lines changed
  • tokio-postgres/src/error

1 file changed

+8
-1
lines changed
 

‎tokio-postgres/src/error/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,14 @@ impl DbError {
309309

310310
impl fmt::Display for DbError {
311311
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
312-
write!(fmt, "{}: {}", self.severity, self.message)
312+
write!(fmt, "{}: {}", self.severity, self.message)?;
313+
if let Some(detail) = &self.detail {
314+
write!(fmt, "DETAIL: {}", detail)?;
315+
}
316+
if let Some(hint) = &self.hint {
317+
write!(fmt, "HINT: {}", hint)?;
318+
}
319+
Ok(())
313320
}
314321
}
315322

0 commit comments

Comments
 (0)
Please sign in to comment.