fast_yaml_parallel/
error.rs

1//! Error types for parallel processing operations.
2
3use std::path::PathBuf;
4
5use fast_yaml_core::ParseError as CoreParseError;
6use thiserror::Error;
7
8/// Unified error type for all parallel operations.
9#[derive(Error, Debug)]
10pub enum Error {
11    /// Failed to parse a document at specific index.
12    #[error("failed to parse document at index {index}")]
13    Parse {
14        /// Zero-based index of the document that failed.
15        index: usize,
16
17        /// The underlying parse error from fast-yaml-core.
18        #[source]
19        source: CoreParseError,
20    },
21
22    /// File I/O error.
23    #[error("failed to read '{path}': {source}")]
24    Io {
25        /// Path to the file that failed.
26        path: PathBuf,
27
28        /// The underlying I/O error.
29        #[source]
30        source: std::io::Error,
31    },
32
33    /// File is not valid UTF-8.
34    #[error("file is not valid UTF-8: {source}")]
35    Utf8 {
36        /// The underlying UTF-8 error.
37        #[source]
38        source: std::str::Utf8Error,
39    },
40
41    /// Failed to format YAML.
42    #[error("format error: {message}")]
43    Format {
44        /// Error message.
45        message: String,
46    },
47
48    /// Failed to write file.
49    #[error("failed to write '{path}': {source}")]
50    Write {
51        /// Path to the file that failed.
52        path: PathBuf,
53
54        /// The underlying I/O error.
55        #[source]
56        source: std::io::Error,
57    },
58
59    /// Input too large (`DoS` protection).
60    #[error("input size {size} bytes exceeds maximum {max} bytes")]
61    InputTooLarge {
62        /// Actual input size.
63        size: usize,
64
65        /// Maximum allowed size.
66        max: usize,
67    },
68
69    /// Document chunking failed.
70    #[error("chunking failed: {0}")]
71    Chunking(String),
72
73    /// Thread pool error.
74    #[error("thread pool error: {0}")]
75    ThreadPool(String),
76
77    /// Configuration error.
78    #[error("configuration error: {0}")]
79    Config(String),
80}
81
82/// Result type for parallel operations.
83pub type Result<T> = std::result::Result<T, Error>;
84
85impl From<std::str::Utf8Error> for Error {
86    fn from(source: std::str::Utf8Error) -> Self {
87        Self::Utf8 { source }
88    }
89}