feat: Proper error handling

- Bump version to 0.8.0
- Added discord error struct
- All errors now implement std::error::Error
- Implemented error handler instead of relying on default
- Fixed bug where you could send answer on a completed quest
This commit is contained in:
Alexey 2025-12-12 16:52:31 +03:00
commit 99812c5d7c
14 changed files with 163 additions and 138 deletions

View file

@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
use crate::{SquadObject, account::Account, error::Error, quest::Quest};
/// Struct for containing paths to other (de-)serializable things
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
#[serde(default)]
pub struct Config {
/// Path to config directory

View file

@ -23,14 +23,26 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::IsNotAFile(path) => write!(f, "{path:?} is not a file"),
Self::IoError(error) => write!(f, "{error}"),
Self::TomlSerializeError(error) => write!(f, "{error}"),
Self::TomlDeserializeError(error) => write!(f, "{error}"),
Self::IoError(_) => write!(f, "io error"),
Self::TomlSerializeError(_) => write!(f, "TOML serialization error"),
Self::TomlDeserializeError(_) => write!(f, "TOML deserialization error"),
Self::IsNotImplemented => write!(f, "implementation not found"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::IsNotAFile(_) |
Self::IsNotImplemented => None,
Self::IoError(error) => Some(error),
Self::TomlSerializeError(error) => Some(error),
Self::TomlDeserializeError(error) => Some(error),
}
}
}
/// Error related to quest logic
#[derive(Debug)]
#[non_exhaustive]
@ -47,6 +59,8 @@ impl fmt::Display for QuestError {
}
}
impl std::error::Error for QuestError {}
/// Error related to map logic
#[derive(Debug)]
#[non_exhaustive]
@ -68,3 +82,5 @@ impl fmt::Display for MapError {
}
}
}
impl std::error::Error for MapError {}