veloren/server/src/persistence/error.rs
Ben Wallis 1de94a9979 * Replaced diesel with rusqlite and refinery
* Added "migration of migrations" to transfer the data from the __diesel_schema_migrations table to the refinery_schema_history table
* Removed all down migrations as refinery does not support down migrations
* Changed all diesel up migrations to refinery naming format
* Added --sql-log-mode parameter to veloren-server-cli to allow SQL tracing and profiling
* Added /disconnect_all_players admin command
* Added disconnectall CLI command
* Fixes for several potential persistence-related race conditions
2021-04-13 22:05:47 +00:00

48 lines
1.7 KiB
Rust

//! Consolidates rusqlite and validation errors under a common error type
extern crate rusqlite;
use std::fmt;
#[derive(Debug)]
pub enum PersistenceError {
// An invalid asset was returned from the database
AssetError(String),
// The player has already reached the max character limit
CharacterLimitReached,
// An error occurred while establish a db connection
DatabaseConnectionError(rusqlite::Error),
// An error occurred when performing a database action
DatabaseError(rusqlite::Error),
// Unable to load body or stats for a character
CharacterDataError,
SerializationError(serde_json::Error),
ConversionError(String),
OtherError(String),
}
impl fmt::Display for PersistenceError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", match self {
Self::AssetError(error) => error.to_string(),
Self::CharacterLimitReached => String::from("Character limit exceeded"),
Self::DatabaseError(error) => error.to_string(),
Self::DatabaseConnectionError(error) => error.to_string(),
Self::CharacterDataError => String::from("Error while loading character data"),
Self::SerializationError(error) => error.to_string(),
Self::ConversionError(error) => error.to_string(),
Self::OtherError(error) => error.to_string(),
})
}
}
impl From<rusqlite::Error> for PersistenceError {
fn from(error: rusqlite::Error) -> PersistenceError { PersistenceError::DatabaseError(error) }
}
impl From<serde_json::Error> for PersistenceError {
fn from(error: serde_json::Error) -> PersistenceError {
PersistenceError::SerializationError(error)
}
}