Browse Source

simplify compatible error handlers

master
yggverse 2 months ago
parent
commit
274bf490b3
  1. 4
      src/app.rs
  2. 53
      src/app/browser.rs
  3. 12
      src/app/browser/window.rs
  4. 18
      src/app/browser/window/tab.rs
  5. 28
      src/app/browser/window/tab/item.rs

4
src/app.rs

@ -256,9 +256,7 @@ impl App { @@ -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(())

53
src/app/browser.rs

@ -198,18 +198,11 @@ impl Browser { @@ -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 { @@ -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 { @@ -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 { @@ -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(())

12
src/app/browser/window.rs

@ -87,9 +87,7 @@ impl Window { @@ -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 { @@ -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 { @@ -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(())

18
src/app/browser/window/tab.rs

@ -187,9 +187,7 @@ impl Tab { @@ -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 { @@ -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 { @@ -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(())

28
src/app/browser/window/tab/item.rs

@ -109,14 +109,10 @@ impl Item { @@ -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 { @@ -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 { @@ -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 { @@ -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(())

Loading…
Cancel
Save