RowNotFound -> DialogueNotFound

This commit is contained in:
Temirkhan Myrzamadi 2021-05-08 19:00:38 +06:00
parent d14e0a49e9
commit 27eda5759c
6 changed files with 24 additions and 20 deletions

View file

@ -10,7 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Storage::get_dialogue` to obtain a dialogue indexed by a chat ID.
- `RedisStorageError::RowNotFound` to be returned from `RedisStorage::remove_dialogue`.
- `InMemStorageError` with a single variant `RowNotFound` to be returned from `InMemStorage::remove_dialogue`.
- `InMemStorageError` with a single variant `DialogueNotFound` to be returned from `InMemStorage::remove_dialogue`.
- `RedisStorageError::DialogueNotFound` and `SqliteStorageError::DialogueNotFound` to be returned from `Storage::remove_dialogue`.
### Changed

View file

@ -9,7 +9,7 @@ use tokio::sync::Mutex;
pub enum InMemStorageError {
/// Returned from [`InMemStorage::remove_dialogue`].
#[error("row not found")]
RowNotFound,
DialogueNotFound,
}
/// A dialogue storage based on [`std::collections::HashMap`].
@ -46,7 +46,7 @@ where
.lock()
.await
.remove(&chat_id)
.map_or_else(|| Err(InMemStorageError::RowNotFound), |_| Ok(()))
.map_or_else(|| Err(InMemStorageError::DialogueNotFound), |_| Ok(()))
})
}

View file

@ -25,7 +25,7 @@ where
/// Returned from [`RedisStorage::remove_dialogue`].
#[error("row not found")]
RowNotFound,
DialogueNotFound,
}
/// A dialogue storage based on [Redis](https://redis.io/).
@ -66,15 +66,15 @@ where
.await?;
if let redis::Value::Bulk(values) = deleted_rows_count {
if let redis::Value::Int(deleted_rows_count) = values[0] {
match deleted_rows_count {
0 => return Err(RedisStorageError::RowNotFound),
_ => return Ok(())
}
}
}
unreachable!("Must return redis::Value::Bulk(redis::Value::Int(_))");
if let redis::Value::Int(deleted_rows_count) = values[0] {
match deleted_rows_count {
0 => return Err(RedisStorageError::DialogueNotFound),
_ => return Ok(()),
}
}
}
unreachable!("Must return redis::Value::Bulk(redis::Value::Int(_))");
})
}

View file

@ -27,6 +27,10 @@ where
#[error("sqlite error: {0}")]
SqliteError(#[from] sqlx::Error),
/// Returned from [`SqliteStorage::remove_dialogue`].
#[error("row not found")]
DialogueNotFound,
}
impl<S> SqliteStorage<S> {
@ -73,7 +77,7 @@ where
.rows_affected();
if deleted_rows_count == 0 {
return Err(SqliteStorageError::SqliteError(sqlx::Error::RowNotFound));
return Err(SqliteStorageError::DialogueNotFound);
}
Ok(())

View file

@ -74,6 +74,6 @@ where
// Check that a try to remove a non-existing dialogue results in an error.
assert!(matches!(
Arc::clone(&storage).remove_dialogue(1).await.unwrap_err(),
RedisStorageError::RowNotFound
RedisStorageError::DialogueNotFound
));
}

View file

@ -68,9 +68,8 @@ where
test_dialogues!(storage, None, None, None);
// Check that a try to remove a non-existing dialogue results in an error.
let err = Arc::clone(&storage).remove_dialogue(1).await.unwrap_err();
match err {
SqliteStorageError::SqliteError(err) => assert!(matches!(err, sqlx::Error::RowNotFound)),
_ => panic!("Must be sqlx::Error::RowNotFound"),
}
assert!(matches!(
Arc::clone(&storage).remove_dialogue(1).await.unwrap_err(),
SqliteStorageError::DialogueNotFound
));
}