-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Refactor
Currently, we rely on the std library error types to propagate to the client our own errors. This is one example.
async fn find_by_pk_with<'a, R, I>(
value: &'a dyn canyon_sql::core::QueryParameter<'a>,
input: I
) -> Result<Option<#ty>, Box<(dyn std::error::Error + Send + Sync + 'a)>>
where
I: canyon_sql::core::DbConnection + Send + 'a,
R: RowMapper
{
Err(
std::io::Error::new(
std::io::ErrorKind::Unsupported,
"You can't use the 'find_by_pk_with' associated function on a \
CanyonEntity that does not have a #[primary_key] annotation. \
If you need to perform an specific search, use the Querybuilder instead."
).into_inner().unwrap()
)
}- The snippet above belongs to the
countmacro
There's some smells there. But the most important ones w'd be to get rid out of the inlined str there (could be in a static str elsewhere), the use of an incorrect Err type, and the required conversion (on the .into_inner())
The idea is to start to create custom error variants under a enumerated type CanyonError, so any variant can hold any arbitrary message or information.
Furthermore, this w'd be an intermediate step to get rid out of the ... impl std::Err::Error + ... syntax on all of the return types, for something more concise and "static", let's say.
Metadata
Metadata
Assignees
Labels
No labels