From a77a1c8b42589b5495943828ffd02505c0749eb6 Mon Sep 17 00:00:00 2001 From: adlee-was-taken Date: Sat, 11 Apr 2026 22:53:19 -0400 Subject: [PATCH] feat: add IdfotoError enum with thiserror --- crates/idfoto-core/src/error.rs | 42 ++++++++++++++++++++++++++++++++- crates/idfoto-core/src/lib.rs | 1 + 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/crates/idfoto-core/src/error.rs b/crates/idfoto-core/src/error.rs index 63391e4..c509fa3 100644 --- a/crates/idfoto-core/src/error.rs +++ b/crates/idfoto-core/src/error.rs @@ -1 +1,41 @@ -// Error types will be filled in Task 2 +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum IdfotoError { + #[error("key derivation failed: {0}")] + Kdf(String), + + #[error("encryption failed: {0}")] + Encrypt(String), + + #[error("decryption failed: wrong key or corrupted data")] + Decrypt, + + #[error("invalid vault format: {0}")] + Format(String), + + #[error("entry not found: {0}")] + EntryNotFound(String), + + #[error("imgsecret: {0}")] + ImgSecret(String), + + #[error("image too small: need at least {min_width}x{min_height}, got {actual_width}x{actual_height}")] + ImageTooSmall { + min_width: u32, + min_height: u32, + actual_width: u32, + actual_height: u32, + }, + + #[error("extraction failed: no valid secret found in image")] + ExtractionFailed, + + #[error("json error: {0}")] + Json(#[from] serde_json::Error), + + #[error("device key error: {0}")] + DeviceKey(String), +} + +pub type Result = std::result::Result; diff --git a/crates/idfoto-core/src/lib.rs b/crates/idfoto-core/src/lib.rs index a91e735..92a114f 100644 --- a/crates/idfoto-core/src/lib.rs +++ b/crates/idfoto-core/src/lib.rs @@ -1 +1,2 @@ pub mod error; +pub use error::{IdfotoError, Result};