Files
khadhroony-bobobot/kb_lib/src/error.rs
2026-04-23 00:07:13 +02:00

71 lines
2.4 KiB
Rust

// file: kb_lib/src/error.rs
//! Shared error type for `kb_lib`.
/// Global error type used by the `kb_lib` crate.
///
/// The project intentionally avoids `anyhow` and `thiserror`, so this
/// enum centralizes the main error families with explicit textual messages.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum KbError {
/// Configuration error.
Config(std::string::String),
/// Filesystem or standard I/O error.
Io(std::string::String),
/// JSON serialization or deserialization error.
Json(std::string::String),
/// Tracing initialization or logging error.
Tracing(std::string::String),
/// HTTP transport error.
Http(std::string::String),
/// WebSocket transport error.
Ws(std::string::String),
/// Database error.
Db(std::string::String),
/// Invalid internal state error.
InvalidState(std::string::String),
/// Operation requested while the client is not connected.
NotConnected(std::string::String),
/// Placeholder for a feature intentionally scheduled for a later version.
NotImplemented(std::string::String),
}
impl std::fmt::Display for KbError {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Config(message) => {
write!(formatter, "configuration error: {message}")
}
Self::Io(message) => {
write!(formatter, "io error: {message}")
}
Self::Json(message) => {
write!(formatter, "json error: {message}")
}
Self::Tracing(message) => {
write!(formatter, "tracing error: {message}")
}
Self::Http(message) => {
write!(formatter, "http error: {message}")
}
Self::Ws(message) => {
write!(formatter, "websocket error: {message}")
}
Self::Db(message) => {
write!(formatter, "db error: {}", message)
}
Self::InvalidState(message) => {
write!(formatter, "invalid state: {message}")
}
Self::NotConnected(message) => {
write!(formatter, "not connected: {message}")
}
Self::NotImplemented(message) => {
write!(formatter, "not implemented: {message}")
}
}
}
}
impl std::error::Error for KbError {}