Skip to main content

cfgmatic_files/
error.rs

1//! Error types for file operations.
2
3use std::path::PathBuf;
4
5/// Errors that can occur when working with configuration files.
6#[derive(Debug, thiserror::Error)]
7pub enum FileError {
8    /// IO error occurred.
9    #[error("io error: {0}")]
10    Io(#[from] std::io::Error),
11
12    /// File not found in any search location.
13    #[error("config file not found: searched in {locations}")]
14    NotFound {
15        /// The file pattern that was searched for.
16        pattern: String,
17        /// Locations that were searched.
18        locations: String,
19    },
20
21    /// Parse error for a specific format.
22    #[error("failed to parse {format} file at {path}: {source}")]
23    Parse {
24        /// Path to the file.
25        path: PathBuf,
26        /// Format that failed to parse.
27        format: &'static str,
28        /// Original error.
29        source: Box<dyn std::error::Error + Send + Sync>,
30    },
31
32    /// Format not supported (feature not enabled).
33    #[error("format '{format}' not supported (feature not enabled)")]
34    UnsupportedFormat {
35        /// The unsupported format.
36        format: String,
37    },
38
39    /// Serialization error.
40    #[error("serialization error: {0}")]
41    Serialization(String),
42}
43
44/// Result type alias for file operations.
45pub type Result<T> = std::result::Result<T, FileError>;