The DataStoreContext::map_err_sqlx function is used repeatedly throughout the codebase to convert sqlx::Errors into redgold_schema::structs::ErrorInfo. This leads to a lot of repetition and makes the code harder to read.
Instead, we should refactor this function to be more generic and reusable. A good strategy might be to introduce a trait called ToErrorInfo with implementations for common error types like sqlx::Error, std::io::Error, and anyhow::Error. This way, we can simply call .to_error_info() on any error type that implements the trait, instead of having to write out the conversion logic every time.
This will make the code more concise, readable, and maintainable. Additionally, it will make it easier to add support for new error types in the future.
The
DataStoreContext::map_err_sqlx
function is used repeatedly throughout the codebase to convertsqlx::Error
s intoredgold_schema::structs::ErrorInfo
. This leads to a lot of repetition and makes the code harder to read.Instead, we should refactor this function to be more generic and reusable. A good strategy might be to introduce a trait called
ToErrorInfo
with implementations for common error types likesqlx::Error
,std::io::Error
, andanyhow::Error
. This way, we can simply call.to_error_info()
on any error type that implements the trait, instead of having to write out the conversion logic every time.This will make the code more concise, readable, and maintainable. Additionally, it will make it easier to add support for new error types in the future.