Skip to main content

fsearch/
error.rs

1// File: src\error.rs
2// Author: Hadi Cahyadi <cumulus13@gmail.com>
3// Date: 2026-05-11
4// Description:
5// License: MIT
6
7//! Error types for the `fsearch` library.
8
9use thiserror::Error;
10
11/// All errors that can be produced by the library.
12#[derive(Debug, Error)]
13#[allow(dead_code)]
14pub enum FsearchError {
15    // ── Search errors ─────────────────────────────────────────────────────────
16    #[error("🚫 Directory does not exist: {0}")]
17    DirectoryNotFound(String),
18
19    #[error("🚫 Path is not a directory: {0}")]
20    NotADirectory(String),
21
22    #[error("❌ Invalid depth: must be >= 0, got {0}")]
23    InvalidDepth(i64),
24
25    #[error("❌ Invalid pattern '{pattern}': {reason}")]
26    InvalidPattern { pattern: String, reason: String },
27
28    // ── Duplicate errors ──────────────────────────────────────────────────────
29    #[error("🔍 Hash algorithm '{0}' is not supported (use 'md5' or 'sha256')")]
30    UnsupportedHashAlgorithm(String),
31
32    // ── IO errors ─────────────────────────────────────────────────────────────
33    #[error("📁 IO error on '{path}': {source}")]
34    Io {
35        path: String,
36        #[source]
37        source: std::io::Error,
38    },
39
40    #[error("🔒 Permission denied: {0}")]
41    PermissionDenied(String),
42
43    // ── Config errors ─────────────────────────────────────────────────────────
44    #[error("⚙️  Config error: {0}")]
45    Config(String),
46
47    #[error("⚙️  Config parse error in '{path}': {source}")]
48    ConfigParse {
49        path: String,
50        #[source]
51        source: toml::de::Error,
52    },
53
54    // ── Interrupt ─────────────────────────────────────────────────────────────
55    #[error("🛑 Operation interrupted by user")]
56    Interrupted,
57}
58
59/// Convenience alias used throughout the library.
60pub type FsearchResult<T> = Result<T, FsearchError>;