diff --git a/sea-orm-macros/src/derives/column.rs b/sea-orm-macros/src/derives/column.rs index c60a91d692..3a0f9314f9 100644 --- a/sea-orm-macros/src/derives/column.rs +++ b/sea-orm-macros/src/derives/column.rs @@ -91,17 +91,6 @@ pub fn impl_col_from_str(ident: &Ident, data: &Data) -> syn::Result ) }); - let entity_name = data_enum - .variants - .first() - .map(|column| { - let column_iden = column.ident.clone(); - quote!( - #ident::#column_iden.entity_name().to_string() - ) - }) - .unwrap(); - Ok(quote!( #[automatically_derived] impl std::str::FromStr for #ident { @@ -110,7 +99,7 @@ pub fn impl_col_from_str(ident: &Ident, data: &Data) -> syn::Result fn from_str(s: &str) -> std::result::Result { match s { #(#columns),*, - _ => Err(sea_orm::ColumnFromStrErr{ string: s.to_owned(), entity: #entity_name }), + _ => Err(sea_orm::ColumnFromStrErr(s.to_owned())), } } } diff --git a/src/database/mock.rs b/src/database/mock.rs index a1dbc795b3..2c5b8d38e8 100644 --- a/src/database/mock.rs +++ b/src/database/mock.rs @@ -102,7 +102,9 @@ impl MockDatabaseTrait for MockDatabase { result: ExecResultHolder::Mock(std::mem::take(&mut self.exec_results[counter])), }) } else { - Err(DbErr::Query("`exec_results` buffer is empty.".to_owned())) + Err(DbErr::Query(RuntimeErr::Internal( + "`exec_results` buffer is empty.".to_owned(), + ))) } } @@ -121,7 +123,9 @@ impl MockDatabaseTrait for MockDatabase { }) .collect()) } else { - Err(DbErr::Query("`query_results` buffer is empty.".to_owned())) + Err(DbErr::Query(RuntimeErr::Internal( + "`query_results` buffer is empty.".to_owned(), + ))) } } @@ -176,7 +180,7 @@ impl MockRow { where T: ValueType, { - T::try_from(self.values.get(col).unwrap().clone()).map_err(|e| DbErr::Query(e.to_string())) + T::try_from(self.values.get(col).unwrap().clone()).map_err(|e| DbErr::Type(e.to_string())) } /// An iterator over the keys and values of a mock row diff --git a/src/entity/column.rs b/src/entity/column.rs index 6f946f51b6..8dbff6ea41 100644 --- a/src/entity/column.rs +++ b/src/entity/column.rs @@ -521,7 +521,7 @@ mod tests { )); assert!(matches!( fruit::Column::from_str("does_not_exist"), - Err(crate::ColumnFromStrErr { .. }) + Err(crate::ColumnFromStrErr(_)) )); } diff --git a/src/error.rs b/src/error.rs index 26bd5ddc2b..34a828fb65 100644 --- a/src/error.rs +++ b/src/error.rs @@ -76,10 +76,5 @@ impl Eq for DbErr {} /// Error during `impl FromStr for Entity::Column` #[derive(Error, Debug)] -#[error("Failed to match \"{string}\" as Column for `{entity}`")] -pub struct ColumnFromStrErr { - /// Source of error - pub string: String, - /// Entity this column belongs to - pub entity: String, -} +#[error("Failed to match \"{0}\" as Column")] +pub struct ColumnFromStrErr(pub String); diff --git a/src/executor/query.rs b/src/executor/query.rs index f27b1a2d90..110aa9eeeb 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -816,20 +816,20 @@ try_from_u64_err!(uuid::Uuid); #[cfg(test)] mod tests { use super::TryGetError; - use crate::error::DbErr; + use crate::error::*; #[test] fn from_try_get_error() { // TryGetError::DbErr - let try_get_error = TryGetError::DbErr(DbErr::Query("expected error message".to_owned())); + let try_get_error = TryGetError::DbErr(DbErr::Query(RuntimeErr::Internal("expected error message".to_owned()))); assert_eq!( DbErr::from(try_get_error), - DbErr::Query("expected error message".to_owned()) + DbErr::Query(RuntimeErr::Internal("expected error message".to_owned())) ); // TryGetError::Null let try_get_error = TryGetError::Null("column".to_owned()); - let expected = "error occurred while decoding column: Null".to_owned(); - assert_eq!(DbErr::from(try_get_error), DbErr::Query(expected)); + let expected = "A null value was encountered while decoding column".to_owned(); + assert_eq!(DbErr::from(try_get_error), DbErr::Type(expected)); } }