redgold-io / redgold

p2p database / compute engine for portfolio contracts
https://redgold.io
MIT License
16 stars 3 forks source link

Refactor DataStoreContext::map_err_sqlx function to reduce repetition #629

Open redgold-ai opened 3 months ago

redgold-ai commented 3 months ago

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.