diff --git a/src/profile.rs b/src/profile.rs
index f99b1e25..3cd6993f 100644
--- a/src/profile.rs
+++ b/src/profile.rs
@@ -59,25 +59,24 @@ impl Profile {
// Init writable connection
let mut connection = match connection.write() {
Ok(connection) => connection,
- Err(e) => todo!("{e}"),
+ Err(reason) => todo!("{reason}"),
};
// Init new transaction
let transaction = match connection.transaction() {
Ok(transaction) => transaction,
- Err(e) => todo!("{e}"),
+ Err(reason) => todo!("{reason}"),
};
// Begin migration
match migrate(&transaction) {
Ok(_) => {
// Confirm changes
- match transaction.commit() {
- Ok(_) => {} // @TODO
- Err(e) => todo!("{e}"),
+ if let Err(reason) = transaction.commit() {
+ todo!("{reason}")
}
}
- Err(e) => todo!("{e}"),
+ Err(reason) => todo!("{reason}"),
}
} // unlock database
@@ -85,18 +84,27 @@ impl Profile {
let database = Rc::new(Database::new(connection.clone()));
// Get active profile or create new one
- let profile_id = Rc::new(match database.active() {
+ let profile_id = Rc::new(match database.active().unwrap() {
Some(profile) => profile.id,
None => match database.add(true, DateTime::now_local().unwrap(), None) {
Ok(id) => id,
- Err(_) => todo!(),
+ Err(reason) => todo!("{:?}", reason),
},
});
+ // Init bookmark component @TODO handle errors
+ let bookmark = Rc::new(Bookmark::new(connection.clone(), profile_id.clone()));
+
+ // Init identity component
+ let identity = Rc::new(match Identity::new(connection, profile_id) {
+ Ok(result) => result,
+ Err(reason) => todo!("{:?}", reason),
+ });
+
// Result
Self {
- bookmark: Rc::new(Bookmark::new(connection.clone(), profile_id.clone())),
- identity: Rc::new(Identity::new(connection, profile_id).unwrap()), // @TODO handle
+ bookmark,
+ identity,
database,
config_path,
}
@@ -105,8 +113,8 @@ impl Profile {
pub fn migrate(tx: &Transaction) -> Result<(), String> {
// Migrate self components
- if let Err(e) = database::init(tx) {
- return Err(e.to_string());
+ if let Err(reason) = database::init(tx) {
+ return Err(reason.to_string());
}
// Delegate migration to children components
diff --git a/src/profile/bookmark/memory.rs b/src/profile/bookmark/memory.rs
index efcb51a3..51878a5a 100644
--- a/src/profile/bookmark/memory.rs
+++ b/src/profile/bookmark/memory.rs
@@ -24,7 +24,7 @@ impl Memory {
/// * validate record with same key does not exist yet
pub fn add(&self, request: String, id: i64) -> Result<(), Error> {
match self.index.borrow_mut().insert(request, id) {
- Some(_) => Err(Error::Overwrite), // @TODO prevent?
+ Some(key) => Err(Error::Overwrite(key)), // @TODO prevent?
None => Ok(()),
}
}
diff --git a/src/profile/bookmark/memory/error.rs b/src/profile/bookmark/memory/error.rs
index 09edab81..ed0b40ff 100644
--- a/src/profile/bookmark/memory/error.rs
+++ b/src/profile/bookmark/memory/error.rs
@@ -1,5 +1,5 @@
#[derive(Debug)]
pub enum Error {
NotFound,
- Overwrite,
+ Overwrite(i64),
}
diff --git a/src/profile/database.rs b/src/profile/database.rs
index d5df732c..b86dc078 100644
--- a/src/profile/database.rs
+++ b/src/profile/database.rs
@@ -24,71 +24,45 @@ impl Database {
// Getters
/// Get all records
- pub fn records(&self) -> Vec
{
+ pub fn records(&self) -> Result, Error> {
let readable = self.connection.read().unwrap();
- let tx = readable.unchecked_transaction().unwrap();
- select(&tx).unwrap()
+ let tx = readable.unchecked_transaction()?;
+ select(&tx)
}
/// Get active profile record if exist
- pub fn active(&self) -> Option {
- self.records().into_iter().find(|record| record.is_active)
+ pub fn active(&self) -> Result