mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
implement to_string method, prevent memory index overwrite on validation step
This commit is contained in:
parent
58ed923bc7
commit
cda94cba2e
@ -138,21 +138,21 @@ impl Gemini {
|
|||||||
match option {
|
match option {
|
||||||
// Activate identity for `auth_uri`
|
// Activate identity for `auth_uri`
|
||||||
Some(profile_identity_gemini_id) => {
|
Some(profile_identity_gemini_id) => {
|
||||||
profile
|
if let Err(reason) = profile
|
||||||
.identity
|
.identity
|
||||||
.gemini
|
.gemini
|
||||||
.auth
|
.auth
|
||||||
.apply(profile_identity_gemini_id, auth_url.as_str())
|
.apply(profile_identity_gemini_id, auth_url.as_str())
|
||||||
.unwrap();
|
{
|
||||||
|
todo!("{}", reason.to_string())
|
||||||
|
};
|
||||||
}
|
}
|
||||||
// Remove all identity auths for `auth_uri`
|
// Remove all identity auths for `auth_uri`
|
||||||
None => {
|
None => {
|
||||||
profile
|
if let Err(reason) = profile.identity.gemini.auth.remove(auth_url.as_str())
|
||||||
.identity
|
{
|
||||||
.gemini
|
todo!("{}", reason.to_string())
|
||||||
.auth
|
};
|
||||||
.remove(auth_url.as_str())
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,3 +3,12 @@ pub enum Error {
|
|||||||
Database(sqlite::Error),
|
Database(sqlite::Error),
|
||||||
Memory(super::memory::Error),
|
Memory(super::memory::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Error {
|
||||||
|
pub fn to_string(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Database(reason) => format!("Database error: {}", reason.to_string()),
|
||||||
|
Self::Memory(reason) => format!("Memory error: {}", reason.to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -23,12 +23,17 @@ impl Memory {
|
|||||||
/// Add new record with `url` as key and `profile_identity_gemini_id` as value
|
/// Add new record with `url` as key and `profile_identity_gemini_id` as value
|
||||||
/// * validate record with same key does not exist yet
|
/// * validate record with same key does not exist yet
|
||||||
pub fn add(&self, url: String, profile_identity_gemini_id: i64) -> Result<(), Error> {
|
pub fn add(&self, url: String, profile_identity_gemini_id: i64) -> Result<(), Error> {
|
||||||
match self
|
// Borrow shared index access
|
||||||
.index
|
let mut index = self.index.borrow_mut();
|
||||||
.borrow_mut()
|
|
||||||
.insert(url, profile_identity_gemini_id)
|
// Prevent existing key overwrite
|
||||||
{
|
if index.contains_key(&url) {
|
||||||
Some(key) => Err(Error::Overwrite(key)), // @TODO prevent?
|
return Err(Error::Overwrite(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Slot should be free, let check it twice
|
||||||
|
match index.insert(url, profile_identity_gemini_id) {
|
||||||
|
Some(_) => return Err(Error::Unexpected),
|
||||||
None => Ok(()),
|
None => Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,18 @@
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Clear,
|
Clear,
|
||||||
Overwrite(i64),
|
Overwrite(String),
|
||||||
|
Unexpected,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error {
|
||||||
|
pub fn to_string(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Clear => format!("Could not cleanup memory index"),
|
||||||
|
Self::Overwrite(key) => {
|
||||||
|
format!("Overwrite attempt for existing record `{key}`")
|
||||||
|
}
|
||||||
|
Self::Unexpected => format!("Unexpected error"),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user