0.0.2
This commit is contained in:
68
kb_lib/src/error.rs
Normal file
68
kb_lib/src/error.rs
Normal 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 {}
|
||||
Reference in New Issue
Block a user