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 {
} }
// Delegate migration to childs // Delegate migration to childs
if let Err(e) = Browser::migrate(&tx) { Browser::migrate(&tx)?;
return Err(e.to_string());
}
// Success // Success
Ok(()) Ok(())

53
src/app/browser.rs

@ -198,18 +198,11 @@ impl Browser {
match Database::delete(transaction, &record.id) { match Database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
if let Err(e) = self.window.clean(transaction, &record.id) { self.window.clean(transaction, &record.id)?;
return Err(e.to_string()); self.widget.clean(transaction, &record.id)?;
}
if let Err(e) = self.widget.clean(transaction, &record.id) {
return Err(e.to_string());
}
/* @TODO /* @TODO
if let Err(e) = self.header.clean(transaction, &record.id) { self.header.clean(transaction, &record.id)?; */
return Err(e.to_string());
} */
} }
Err(e) => return Err(e.to_string()), Err(e) => return Err(e.to_string()),
} }
@ -226,18 +219,11 @@ impl Browser {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to childs // Delegate restore action to childs
if let Err(e) = self.widget.restore(transaction, &record.id) { self.widget.restore(transaction, &record.id)?;
return Err(e.to_string()); self.window.restore(transaction, &record.id)?;
}
if let Err(e) = self.window.restore(transaction, &record.id) {
return Err(e.to_string());
}
/* @TODO /* @TODO
if let Err(e) = self.header.restore(transaction, &record.id) { self.header.restore(transaction, &record.id)?; */
return Err(e.to_string());
} */
} }
} }
Err(e) => return Err(e.to_string()), Err(e) => return Err(e.to_string()),
@ -252,18 +238,11 @@ impl Browser {
let id = Database::last_insert_id(transaction); let id = Database::last_insert_id(transaction);
// Delegate save action to childs // Delegate save action to childs
if let Err(e) = self.widget.save(transaction, &id) { self.widget.save(transaction, &id)?;
return Err(e.to_string()); self.window.save(transaction, &id)?;
}
if let Err(e) = self.window.save(transaction, &id) {
return Err(e.to_string());
}
/* @TODO /* @TODO
if let Err(e) = self.header.save(transaction, &id) { self.header.save(transaction, &id)?; */
return Err(e.to_string());
} */
} }
Err(e) => return Err(e.to_string()), Err(e) => return Err(e.to_string()),
} }
@ -285,17 +264,9 @@ impl Browser {
// Delegate migration to childs // Delegate migration to childs
/* @TODO /* @TODO
if let Err(e) = Header::migrate(&tx) { Header::migrate(&tx)?; */
return Err(e.to_string()); Window::migrate(&tx)?;
} */ Widget::migrate(&tx)?;
if let Err(e) = Window::migrate(&tx) {
return Err(e.to_string());
}
if let Err(e) = Widget::migrate(&tx) {
return Err(e.to_string());
}
// Success // Success
Ok(()) Ok(())

12
src/app/browser/window.rs

@ -87,9 +87,7 @@ impl Window {
match Database::delete(transaction, &record.id) { match Database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
if let Err(e) = self.tab.clean(transaction, &record.id) { self.tab.clean(transaction, &record.id)?;
return Err(e.to_string());
}
} }
Err(e) => return Err(e.to_string()), Err(e) => return Err(e.to_string()),
} }
@ -106,9 +104,7 @@ impl Window {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to childs // Delegate restore action to childs
if let Err(e) = self.tab.restore(transaction, &record.id) { self.tab.restore(transaction, &record.id)?;
return Err(e.to_string());
}
} }
} }
Err(e) => return Err(e.to_string()), Err(e) => return Err(e.to_string()),
@ -155,9 +151,7 @@ impl Window {
} }
// Delegate migration to childs // Delegate migration to childs
if let Err(e) = Tab::migrate(&tx) { Tab::migrate(&tx)?;
return Err(e.to_string());
}
// Success // Success
Ok(()) Ok(())

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

@ -187,9 +187,7 @@ impl Tab {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
for (_, item) in self.index.borrow().iter() { for (_, item) in self.index.borrow().iter() {
if let Err(e) = item.clean(transaction, &record.id) { item.clean(transaction, &record.id)?
return Err(e.to_string());
}
} }
} }
Err(e) => return Err(e.to_string()), Err(e) => return Err(e.to_string()),
@ -256,16 +254,14 @@ impl Tab {
let mut page_number = 0; let mut page_number = 0;
for (_, item) in self.index.borrow().iter() { for (_, item) in self.index.borrow().iter() {
if let Err(e) = item.save( item.save(
transaction, transaction,
&id, &id,
&match self.widget.gobject().current_page() { &match self.widget.gobject().current_page() {
Some(number) => number == page_number, Some(number) => number == page_number,
None => false, None => false,
}, },
) { )?;
return Err(e.to_string());
}
page_number += 1; page_number += 1;
} }
@ -308,14 +304,10 @@ impl Tab {
} }
// Delegate migration to childs // Delegate migration to childs
if let Err(e) = Item::migrate(&tx) { Item::migrate(&tx)?;
return Err(e.to_string());
}
/* @TODO /* @TODO
if let Err(e) = Page::migrate(&tx) { Page::migrate(&tx)?; */
return Err(e.to_string());
} */
// Success // Success
Ok(()) Ok(())

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

@ -109,14 +109,10 @@ impl Item {
match Database::delete(transaction, &record.id) { match Database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to the item childs // Delegate clean action to the item childs
if let Err(e) = self.label.clean(transaction, &record.id) { self.label.clean(transaction, &record.id)?;
return Err(e.to_string());
}
/* @TODO /* @TODO
if let Err(e) = self.page.clean(transaction, &record.id) { self.page.clean(transaction, &record.id)?;*/
return Err(e.to_string());
} */
} }
Err(e) => return Err(e.to_string()), Err(e) => return Err(e.to_string()),
} }
@ -158,9 +154,7 @@ impl Item {
)); ));
// Delegate restore action to the item childs // Delegate restore action to the item childs
if let Err(e) = item.label.restore(transaction, &record.id) { item.label.restore(transaction, &record.id)?;
return Err(e.to_string());
}
// Result // Result
items.push(item); items.push(item);
@ -183,14 +177,10 @@ impl Item {
let id = Database::last_insert_id(transaction); let id = Database::last_insert_id(transaction);
// Delegate save action to childs // Delegate save action to childs
if let Err(e) = self.label.save(transaction, &id) { self.label.save(transaction, &id)?;
return Err(e.to_string());
}
/* @TODO /* @TODO
if let Err(e) = self.page.save(transaction, &id) { self.page.save(transaction, &id)?; */
return Err(e.to_string());
} */
} }
Err(e) => return Err(e.to_string()), Err(e) => return Err(e.to_string()),
} }
@ -231,14 +221,10 @@ impl Item {
} }
// Delegate migration to childs // Delegate migration to childs
if let Err(e) = Label::migrate(&tx) { Label::migrate(&tx)?;
return Err(e.to_string());
}
/* @TODO /* @TODO
if let Err(e) = Page::migrate(&tx) { Page::migrate(&tx)? */
return Err(e.to_string());
} */
// Success // Success
Ok(()) Ok(())

Loading…
Cancel
Save