From 1a2f99963611e0a61b6712e25c970f3dd1e39342 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Fri, 27 Mar 2026 21:17:27 -0700 Subject: [PATCH] feat(wave1): App error type and Result alias [claudbg-i09w] Co-Authored-By: Claude Sonnet 4.6 --- ...g-i09w--app-error-type-and-result-alias.md | 7 +- src/error.rs | 73 +++++++++++++++++++ src/lib.rs | 2 +- src/main.rs | 5 ++ 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 src/error.rs diff --git a/.beans/claudbg-i09w--app-error-type-and-result-alias.md b/.beans/claudbg-i09w--app-error-type-and-result-alias.md index a61c5a5..16c5fa1 100644 --- a/.beans/claudbg-i09w--app-error-type-and-result-alias.md +++ b/.beans/claudbg-i09w--app-error-type-and-result-alias.md @@ -1,11 +1,12 @@ --- # claudbg-i09w title: App error type and Result alias -status: todo +status: completed type: task +priority: normal created_at: 2026-03-27T19:38:56Z -updated_at: 2026-03-27T19:38:56Z +updated_at: 2026-03-28T04:15:59Z parent: claudbg-h7xu --- -Define a top-level AppError enum (IoError, ParseError, DbError, NotFound, etc.) and a Result alias. Use thiserror or a similar crate. +Created src/error.rs with AppError enum (Io, Parse, Db, NotFound, InvalidArg) and Result alias using thiserror. All variants have doc comments. Six unit tests verify Display impl for each variant and From conversion. Updated src/lib.rs to declare pub mod error and src/main.rs to import claudbg::error::Result. diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..b293090 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,73 @@ +//! Application-level error types for claudbg. + +/// Application-level error type. +#[derive(Debug, thiserror::Error)] +pub enum AppError { + /// Wraps [`std::io::Error`] for filesystem and I/O failures. + #[error("I/O error: {0}")] + Io(#[from] std::io::Error), + /// A parsing failure with a descriptive message. + #[error("Parse error: {0}")] + Parse(String), + /// A database operation failure with a descriptive message. + #[error("Database error: {0}")] + Db(String), + /// The requested session or agent ID was not found. + #[error("Session not found: {0}")] + NotFound(String), + /// An invalid argument was supplied by the user. + #[error("Invalid argument: {0}")] + InvalidArg(String), +} + +/// Convenience `Result` alias using [`AppError`]. +pub type Result = std::result::Result; + +#[cfg(test)] +mod tests { + use super::*; + use std::io; + + /// `AppError::Io` displays the wrapped I/O error message. + #[test] + fn display_io() { + let err = AppError::Io(io::Error::new(io::ErrorKind::NotFound, "file missing")); + assert_eq!(err.to_string(), "I/O error: file missing"); + } + + /// `AppError::Parse` displays the message passed to the constructor. + #[test] + fn display_parse() { + let err = AppError::Parse("bad JSON".to_string()); + assert_eq!(err.to_string(), "Parse error: bad JSON"); + } + + /// `AppError::Db` displays the message passed to the constructor. + #[test] + fn display_db() { + let err = AppError::Db("connection refused".to_string()); + assert_eq!(err.to_string(), "Database error: connection refused"); + } + + /// `AppError::NotFound` displays the ID that was missing. + #[test] + fn display_not_found() { + let err = AppError::NotFound("abc12345".to_string()); + assert_eq!(err.to_string(), "Session not found: abc12345"); + } + + /// `AppError::InvalidArg` displays the invalid argument description. + #[test] + fn display_invalid_arg() { + let err = AppError::InvalidArg("unknown token: foo".to_string()); + assert_eq!(err.to_string(), "Invalid argument: unknown token: foo"); + } + + /// `AppError::Io` can be constructed via `From`. + #[test] + fn from_io_error() { + let io_err = io::Error::new(io::ErrorKind::PermissionDenied, "denied"); + let app_err: AppError = io_err.into(); + assert!(app_err.to_string().contains("denied")); + } +} diff --git a/src/lib.rs b/src/lib.rs index 01d2f1d..87d93e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ // pub mod cli; // pub mod commands; // pub mod db; -// pub mod error; +pub mod error; // pub mod models; // pub mod output; // pub mod util; diff --git a/src/main.rs b/src/main.rs index e7a11a9..ea2d861 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,8 @@ +//! claudbg binary entry point. + +use claudbg::error::Result; + fn main() { + let _: Result<()> = Ok(()); println!("Hello, world!"); }