From 3f3a2df07264df77caaeab6293897d8251431229 Mon Sep 17 00:00:00 2001 From: davidemazzocchi Date: Mon, 16 Mar 2026 08:21:55 +0100 Subject: [PATCH] feat: add Display implementaion for public and internal FailedTo --- 01.workspace/heave/src/str/failed_to.rs | 26 ++++++++++++++++++- .../heave/src/str/sqlite_failed_to.rs | 17 ++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/01.workspace/heave/src/str/failed_to.rs b/01.workspace/heave/src/str/failed_to.rs index f13c87a..abfeffa 100644 --- a/01.workspace/heave/src/str/failed_to.rs +++ b/01.workspace/heave/src/str/failed_to.rs @@ -59,6 +59,30 @@ impl std::error::Error for FailedTo {} impl std::fmt::Display for FailedTo { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> { - todo!() + match self { + FailedTo::ComposeFilter => write!(f, "Failed to compose filter statement"), + FailedTo::ConvertEntity => write!(f, "Failed to convert from Entity to type"), + FailedTo::ConvertObject => write!(f, "Failed to convert from type to Entity"), + FailedTo::ConvertValue => write!(f, "Failed to convert from Value to type"), + FailedTo::ExecutePredicate(errors) => { + write!(f, "Failed to execute predicate: ")?; + for (i, err) in errors.iter().enumerate() { + if i > 0 { + write!(f, "; ")?; + } + write!(f, "{}", err)?; + } + Ok(()) + } + FailedTo::InitDatabase => write!(f, "Failed to initialize the database"), + FailedTo::LoadFromDB => write!(f, "Failed to load data from the database"), + FailedTo::LockCatalog => { + write!(f, "Failed to lock catalog in a multithread environment") + } + FailedTo::MapAttribute => write!(f, "Failed to map a database row to an attribute"), + FailedTo::MapEntity => write!(f, "Failed to map a database row to an entity"), + FailedTo::PersistCatalog => write!(f, "Failed to persist the catalog to the database"), + FailedTo::SQLite(e) => write!(f, "SQLite error: {}", e), + } } } diff --git a/01.workspace/heave/src/str/sqlite_failed_to.rs b/01.workspace/heave/src/str/sqlite_failed_to.rs index 29ff835..bbf22a8 100644 --- a/01.workspace/heave/src/str/sqlite_failed_to.rs +++ b/01.workspace/heave/src/str/sqlite_failed_to.rs @@ -18,3 +18,20 @@ pub enum FailedTo { /// Failed to prepare a SQL statement for execution. PrepareStatement(rusqlite::Error), } + +impl std::error::Error for FailedTo{} + +impl std::fmt::Display for FailedTo { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> { + match self { + FailedTo::BeginTransaction(e) => write!(f, "Failed to begin transaction: {}", e), + FailedTo::BuildStatement => write!(f, "Failed to build SQL statement"), + FailedTo::CommitTransaction(e) => write!(f, "Failed to commit transaction: {}", e), + FailedTo::ExecuteBatch(e) => write!(f, "Failed to execute batch: {}", e), + FailedTo::ExecuteQuery(e) => write!(f, "Failed to execute query: {}", e), + FailedTo::ExecuteStatement(e) => write!(f, "Failed to execute statement: {}", e), + FailedTo::OpenConnection(e) => write!(f, "Failed to open connection: {}", e), + FailedTo::PrepareStatement(e) => write!(f, "Failed to prepare statement: {}", e), + } + } +}