simplify compatible error handlers

This commit is contained in:
yggverse 2024-10-08 03:41:51 +03:00
parent 94d56fec4a
commit 274bf490b3
5 changed files with 28 additions and 87 deletions

View File

@ -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(())

View File

@ -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(())

View File

@ -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(())

View File

@ -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(())

View File

@ -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(())