From f0a2cf32aca804a63af71214a1d0b7ef428ff6f0 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Wed, 27 Aug 2025 21:36:44 -0300 Subject: [PATCH] chore: add derive_more and smart-default crates Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) --- Cargo.toml | 2 ++ src/modes/info.rs | 2 +- src/services/error.rs | 27 ++++++++++++++++++++------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bf33aa8..61196cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,8 @@ categories = ["command-line-utilities"] [dependencies] anyhow = "1.0.72" axum = "0.8.4" +derive_more = "1.0" +smart-default = "0.7" base64 = "0.22.1" chrono = "0.4.26" clap = { version = "4.3.10", features = ["derive", "env"] } diff --git a/src/modes/info.rs b/src/modes/info.rs index a4b8206..8a794b0 100644 --- a/src/modes/info.rs +++ b/src/modes/info.rs @@ -47,7 +47,7 @@ pub fn mode_info( show_item(item_with_meta, settings, data_path) } -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] struct ItemInfo { id: i64, timestamp: String, diff --git a/src/services/error.rs b/src/services/error.rs index 2ed96ac..fbe2eed 100644 --- a/src/services/error.rs +++ b/src/services/error.rs @@ -24,11 +24,24 @@ pub enum CoreError { Other(#[from] anyhow::Error), } -impl From for CoreError { - fn from(err: rusqlite_migration::Error) -> Self { - match err { - rusqlite_migration::Error::RusqliteError { err: e, .. } => CoreError::Database(e), - e => CoreError::Other(e.into()), - } - } +use derive_more::From; + +#[derive(Error, Debug, From)] +pub enum CoreError { + #[error("Database error: {0}")] + Database(#[from] rusqlite::Error), + #[error("I/O error: {0}")] + Io(#[from] std::io::Error), + #[error("Item not found with id {0}")] + ItemNotFound(i64), + #[error("Item not found")] + ItemNotFoundGeneric, + #[error("Invalid input: {0}")] + InvalidInput(String), + #[error("Compression error: {0}")] + Compression(String), + #[error(transparent)] + Other(#[from] anyhow::Error), + #[from] + Migration(#[error(ignore)] rusqlite_migration::Error), }