This commit is contained in:
2026-04-20 20:14:40 +02:00
parent 4261291ac1
commit 176fe3db99
21 changed files with 1445 additions and 132 deletions

68
kb_lib/src/error.rs Normal file
View File

@@ -0,0 +1,68 @@
// 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),
/// 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::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 {}