diff --git a/sea-orm-macros/src/derives/active_enum.rs b/sea-orm-macros/src/derives/active_enum.rs index 6823405d5..cfd5454dc 100644 --- a/sea-orm-macros/src/derives/active_enum.rs +++ b/sea-orm-macros/src/derives/active_enum.rs @@ -191,7 +191,7 @@ impl ActiveEnum { fn try_from_value(v: &Self::Value) -> Result { match #val { #( #variant_values => Ok(Self::#variant_idents), )* - _ => Err(sea_orm::DbErr::Query(format!( + _ => Err(sea_orm::DbErr::Type(format!( "unexpected value for {} enum: {}", stringify!(#ident), v diff --git a/src/entity/active_enum.rs b/src/entity/active_enum.rs index 31a65db7a..5eb77b9f2 100644 --- a/src/entity/active_enum.rs +++ b/src/entity/active_enum.rs @@ -15,7 +15,7 @@ use sea_query::{Nullable, Value, ValueType}; /// /// ```rust /// use sea_orm::entity::prelude::*; -/// +/// /// // Using the derive macro /// #[derive(Debug, PartialEq, DeriveActiveEnum)] /// #[sea_orm(rs_type = "String", db_type = "String(Some(1))")] @@ -51,7 +51,7 @@ use sea_query::{Nullable, Value, ValueType}; /// match v.as_ref() { /// "B" => Ok(Self::Big), /// "S" => Ok(Self::Small), -/// _ => Err(DbErr::Query(format!( +/// _ => Err(DbErr::Type(format!( /// "unexpected value for Category enum: {}", /// v /// ))), @@ -138,7 +138,7 @@ mod tests { match v.as_ref() { "B" => Ok(Self::Big), "S" => Ok(Self::Small), - _ => Err(DbErr::Query(format!( + _ => Err(DbErr::Type(format!( "unexpected value for Category enum: {}", v ))), @@ -166,7 +166,7 @@ mod tests { assert_eq!( Category::try_from_value(&"A".to_owned()).err(), - Some(DbErr::Query( + Some(DbErr::Type( "unexpected value for Category enum: A".to_owned() )) ); @@ -180,7 +180,7 @@ mod tests { ); assert_eq!( DeriveCategory::try_from_value(&"A".to_owned()).err(), - Some(DbErr::Query( + Some(DbErr::Type( "unexpected value for DeriveCategory enum: A".to_owned() )) ); @@ -221,7 +221,7 @@ mod tests { assert_eq!($ident::try_from_value(&-10).ok(), Some($ident::Negative)); assert_eq!( $ident::try_from_value(&2).err(), - Some(DbErr::Query(format!( + Some(DbErr::Type(format!( "unexpected value for {} enum: 2", stringify!($ident) ))) @@ -257,7 +257,7 @@ mod tests { assert_eq!($ident::try_from_value(&0).ok(), Some($ident::Small)); assert_eq!( $ident::try_from_value(&2).err(), - Some(DbErr::Query(format!( + Some(DbErr::Type(format!( "unexpected value for {} enum: 2", stringify!($ident) ))) diff --git a/src/error.rs b/src/error.rs index f39aee721..c138009ba 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,10 +1,23 @@ +/// Represents all the errors in SeaORM. #[derive(Debug, PartialEq)] pub enum DbErr { + /// Error occurred while connecting to database engine. Conn(String), + + /// Error occurred while executing SQL statement. Exec(String), + + /// Error occurred while querying SQL statement. Query(String), + + /// Error occurred while updating a non-existing row in database. RecordNotFound(String), + + /// Error occurred while performing custom validation logics in [ActiveModelBehavior](crate::ActiveModelBehavior) Custom(String), + + /// Error occurred while parsing value into [ActiveEnum](crate::ActiveEnum) + Type(String), } impl std::error::Error for DbErr {} @@ -17,6 +30,7 @@ impl std::fmt::Display for DbErr { Self::Query(s) => write!(f, "Query Error: {}", s), Self::RecordNotFound(s) => write!(f, "RecordNotFound Error: {}", s), Self::Custom(s) => write!(f, "Custom Error: {}", s), + Self::Type(s) => write!(f, "Type Error: {}", s), } } }