mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-03-12 09:29:11 +00:00
error: add variants to RuntimeError
This commit is contained in:
parent
ce3c8c5870
commit
e78538a265
1 changed files with 56 additions and 13 deletions
|
@ -32,30 +32,73 @@ pub enum InitError<BackendError: Debug> {
|
|||
|
||||
//---------------------------------------------------------------------------------------------------- RuntimeError
|
||||
/// Database errors that occur _after_ successful initialization.
|
||||
///
|
||||
/// There are no errors for:
|
||||
/// 1. Missing tables
|
||||
/// 2. (De)serialization
|
||||
///
|
||||
/// as `cuprate_database` upholds the invariant that:
|
||||
///
|
||||
/// 1. All tables exist
|
||||
/// 2. (De)serialization never fails
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "borsh",
|
||||
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
|
||||
)]
|
||||
#[derive(thiserror::Error, Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
pub enum RuntimeError {
|
||||
// TODO: replace string with actual error type.
|
||||
pub enum RuntimeError<BackendError: Debug> {
|
||||
/// The given key already existed in the database.
|
||||
///
|
||||
/// An error occurred when attempting to
|
||||
/// serialize the key data into bytes.
|
||||
#[error("serialize error: {0}")]
|
||||
Serialize(String),
|
||||
/// The string inside is the output of
|
||||
/// [`std::any::type_name`] on the key type.
|
||||
#[error("key of type `{0}` already existed")]
|
||||
KeyExists(&'static str),
|
||||
|
||||
// TODO: replace string with actual error type.
|
||||
/// The given key did not exist in the database.
|
||||
///
|
||||
/// An error occurred when attempting to
|
||||
/// deserialize the response value from
|
||||
/// the database.
|
||||
#[error("deserialize error: {0}")]
|
||||
Deserialize(String),
|
||||
/// The string inside is the output of
|
||||
/// [`std::any::type_name`] on the key type.
|
||||
#[error("key/value pair was not found: {0}")]
|
||||
KeyNotFound(&'static str),
|
||||
|
||||
/// TODO
|
||||
/// The database environment has reached
|
||||
/// maximum memory map size, it must be
|
||||
/// increased.
|
||||
//
|
||||
// TODO: `sanakirja` automatically resizes, `heed` does not.
|
||||
// I guess this should be `unreachable!()` for `sanakirja`?
|
||||
#[error("not enough space in database environment memory map")]
|
||||
MapFull,
|
||||
|
||||
/// A database page does not have enough
|
||||
/// space for more key/values.
|
||||
#[error("not enough space in database page")]
|
||||
PageFull,
|
||||
|
||||
/// A [`std::io::Error`].
|
||||
#[error("I/O error: {0}")]
|
||||
Io(#[from] std::io::Error),
|
||||
|
||||
/// The expected database version was not the version found.
|
||||
#[error("database version mismatch: expected {expected}, found {found}")]
|
||||
VersionMismatch {
|
||||
expected: &'static str,
|
||||
found: &'static str,
|
||||
},
|
||||
|
||||
/// The database has reached maximum parallel readers.
|
||||
///
|
||||
/// TODO: this can be used for retry logic in reader threads,
|
||||
/// although, does this error ever actually occur in practice?
|
||||
#[error("database maximum parallel readers reached")]
|
||||
MaxReaders,
|
||||
|
||||
/// An unknown backend-specific error occured.
|
||||
#[error("{DATABASE_BACKEND} error: {0}")]
|
||||
Backend(BackendError),
|
||||
|
||||
// TODO: this could be removed once we have all errors figured out.
|
||||
/// An unknown error occurred.
|
||||
#[error("unknown error: {0}")]
|
||||
Unknown(Cow<'static, str>),
|
||||
|
|
Loading…
Reference in a new issue