From 274bf490b3adad2d9c859501dae97e5cb85c3f90 Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 8 Oct 2024 03:41:51 +0300 Subject: [PATCH] simplify compatible error handlers --- src/app.rs | 4 +-- src/app/browser.rs | 53 +++++++----------------------- src/app/browser/window.rs | 12 ++----- src/app/browser/window/tab.rs | 18 +++------- src/app/browser/window/tab/item.rs | 28 ++++------------ 5 files changed, 28 insertions(+), 87 deletions(-) diff --git a/src/app.rs b/src/app.rs index af92d593..c51ec877 100644 --- a/src/app.rs +++ b/src/app.rs @@ -256,9 +256,7 @@ impl App { } // Delegate migration to childs - if let Err(e) = Browser::migrate(&tx) { - return Err(e.to_string()); - } + Browser::migrate(&tx)?; // Success Ok(()) diff --git a/src/app/browser.rs b/src/app/browser.rs index 1b5ef76f..9445bd21 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -198,18 +198,11 @@ impl Browser { match Database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to childs - if let Err(e) = self.window.clean(transaction, &record.id) { - return Err(e.to_string()); - } - - if let Err(e) = self.widget.clean(transaction, &record.id) { - return Err(e.to_string()); - } + self.window.clean(transaction, &record.id)?; + self.widget.clean(transaction, &record.id)?; /* @TODO - if let Err(e) = self.header.clean(transaction, &record.id) { - return Err(e.to_string()); - } */ + self.header.clean(transaction, &record.id)?; */ } Err(e) => return Err(e.to_string()), } @@ -226,18 +219,11 @@ impl Browser { Ok(records) => { for record in records { // Delegate restore action to childs - if let Err(e) = self.widget.restore(transaction, &record.id) { - return Err(e.to_string()); - } - - if let Err(e) = self.window.restore(transaction, &record.id) { - return Err(e.to_string()); - } + self.widget.restore(transaction, &record.id)?; + self.window.restore(transaction, &record.id)?; /* @TODO - if let Err(e) = self.header.restore(transaction, &record.id) { - return Err(e.to_string()); - } */ + self.header.restore(transaction, &record.id)?; */ } } Err(e) => return Err(e.to_string()), @@ -252,18 +238,11 @@ impl Browser { let id = Database::last_insert_id(transaction); // Delegate save action to childs - if let Err(e) = self.widget.save(transaction, &id) { - return Err(e.to_string()); - } - - if let Err(e) = self.window.save(transaction, &id) { - return Err(e.to_string()); - } + self.widget.save(transaction, &id)?; + self.window.save(transaction, &id)?; /* @TODO - if let Err(e) = self.header.save(transaction, &id) { - return Err(e.to_string()); - } */ + self.header.save(transaction, &id)?; */ } Err(e) => return Err(e.to_string()), } @@ -285,17 +264,9 @@ impl Browser { // Delegate migration to childs /* @TODO - if let Err(e) = Header::migrate(&tx) { - return Err(e.to_string()); - } */ - - if let Err(e) = Window::migrate(&tx) { - return Err(e.to_string()); - } - - if let Err(e) = Widget::migrate(&tx) { - return Err(e.to_string()); - } + Header::migrate(&tx)?; */ + Window::migrate(&tx)?; + Widget::migrate(&tx)?; // Success Ok(()) diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index 85970c67..b72b882c 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -87,9 +87,7 @@ impl Window { match Database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to childs - if let Err(e) = self.tab.clean(transaction, &record.id) { - return Err(e.to_string()); - } + self.tab.clean(transaction, &record.id)?; } Err(e) => return Err(e.to_string()), } @@ -106,9 +104,7 @@ impl Window { Ok(records) => { for record in records { // Delegate restore action to childs - if let Err(e) = self.tab.restore(transaction, &record.id) { - return Err(e.to_string()); - } + self.tab.restore(transaction, &record.id)?; } } Err(e) => return Err(e.to_string()), @@ -155,9 +151,7 @@ impl Window { } // Delegate migration to childs - if let Err(e) = Tab::migrate(&tx) { - return Err(e.to_string()); - } + Tab::migrate(&tx)?; // Success Ok(()) diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index f399654c..a92d3be5 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -187,9 +187,7 @@ impl Tab { Ok(_) => { // Delegate clean action to childs for (_, item) in self.index.borrow().iter() { - if let Err(e) = item.clean(transaction, &record.id) { - return Err(e.to_string()); - } + item.clean(transaction, &record.id)? } } Err(e) => return Err(e.to_string()), @@ -256,16 +254,14 @@ impl Tab { let mut page_number = 0; for (_, item) in self.index.borrow().iter() { - if let Err(e) = item.save( + item.save( transaction, &id, &match self.widget.gobject().current_page() { Some(number) => number == page_number, None => false, }, - ) { - return Err(e.to_string()); - } + )?; page_number += 1; } @@ -308,14 +304,10 @@ impl Tab { } // Delegate migration to childs - if let Err(e) = Item::migrate(&tx) { - return Err(e.to_string()); - } + Item::migrate(&tx)?; /* @TODO - if let Err(e) = Page::migrate(&tx) { - return Err(e.to_string()); - } */ + Page::migrate(&tx)?; */ // Success Ok(()) diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index c5da8e39..abae310e 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -109,14 +109,10 @@ impl Item { match Database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to the item childs - if let Err(e) = self.label.clean(transaction, &record.id) { - return Err(e.to_string()); - } + self.label.clean(transaction, &record.id)?; /* @TODO - if let Err(e) = self.page.clean(transaction, &record.id) { - return Err(e.to_string()); - } */ + self.page.clean(transaction, &record.id)?;*/ } Err(e) => return Err(e.to_string()), } @@ -158,9 +154,7 @@ impl Item { )); // Delegate restore action to the item childs - if let Err(e) = item.label.restore(transaction, &record.id) { - return Err(e.to_string()); - } + item.label.restore(transaction, &record.id)?; // Result items.push(item); @@ -183,14 +177,10 @@ impl Item { let id = Database::last_insert_id(transaction); // Delegate save action to childs - if let Err(e) = self.label.save(transaction, &id) { - return Err(e.to_string()); - } + self.label.save(transaction, &id)?; /* @TODO - if let Err(e) = self.page.save(transaction, &id) { - return Err(e.to_string()); - } */ + self.page.save(transaction, &id)?; */ } Err(e) => return Err(e.to_string()), } @@ -231,14 +221,10 @@ impl Item { } // Delegate migration to childs - if let Err(e) = Label::migrate(&tx) { - return Err(e.to_string()); - } + Label::migrate(&tx)?; /* @TODO - if let Err(e) = Page::migrate(&tx) { - return Err(e.to_string()); - } */ + Page::migrate(&tx)? */ // Success Ok(())