Add Diesel error variant
All checks were successful
Push Workflows / rustfmt (push) Successful in 5s
Push Workflows / tailwind-build (push) Successful in 5s
Push Workflows / test (push) Successful in 17s
Push Workflows / docs (push) Successful in 18s
Push Workflows / clippy (push) Successful in 20s
Push Workflows / build (push) Successful in 52s
Push Workflows / nix-build (push) Successful in 4m50s

This commit is contained in:
2026-06-21 12:28:01 -04:00
parent ff2aba4ec4
commit 1cf1bfcfbc

View File

@@ -249,6 +249,11 @@ impl<E: Into<Error>> Contextualize<Error> for E {
#[derive(Debug, Clone, thiserror::Error, Deserialize, Serialize)]
pub enum ErrorType {
// Using string to represent Diesel errors, because Diesel's Error type is not `Serialize`,
// and Diesel is only available on the server
#[error("Database error: {0}")]
Database(String),
#[error("{0}")]
Error(String),
}
@@ -259,3 +264,11 @@ impl From<ErrorType> for Error {
Error::new_here(err)
}
}
#[cfg(feature = "server")]
impl From<diesel::result::Error> for Error {
#[track_caller]
fn from(err: diesel::result::Error) -> Self {
Error::new_here(ErrorType::Database(format!("{err}")))
}
}