veloren_server/persistence/
error.rs1extern crate rusqlite;
4
5use std::fmt;
6
7#[derive(Debug)]
8pub enum PersistenceError {
9 AssetError(String),
11 CharacterLimitReached,
13 DatabaseConnectionError(rusqlite::Error),
15 DatabaseError(rusqlite::Error),
17 CharacterDataError,
19 SerializationError(serde_json::Error),
20 ConversionError(String),
21 OtherError(String),
22}
23
24impl fmt::Display for PersistenceError {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 write!(f, "{}", match self {
27 Self::AssetError(error) => error.to_string(),
28 Self::CharacterLimitReached => String::from("Character limit exceeded"),
29 Self::DatabaseError(error) => error.to_string(),
30 Self::DatabaseConnectionError(error) => error.to_string(),
31 Self::CharacterDataError => String::from("Error while loading character data"),
32 Self::SerializationError(error) => error.to_string(),
33 Self::ConversionError(error) => error.to_string(),
34 Self::OtherError(error) => error.to_string(),
35 })
36 }
37}
38
39impl From<rusqlite::Error> for PersistenceError {
40 fn from(error: rusqlite::Error) -> PersistenceError { PersistenceError::DatabaseError(error) }
41}
42
43impl From<serde_json::Error> for PersistenceError {
44 fn from(error: serde_json::Error) -> PersistenceError {
45 PersistenceError::SerializationError(error)
46 }
47}