Skip to main content

rusty_pee/
error.rs

1//! Library-level error type for `rusty_pee`.
2//!
3//! Uses `thiserror` to produce typed errors per AD-012; the binary boundary
4//! wraps these in `anyhow::Result` for human-readable diagnostics.
5
6/// Errors returned by the `rusty_pee` library API.
7///
8/// Per FR-028 + FR-029, the enum carries the enum-level `#[non_exhaustive]`
9/// marker (protects future variant additions) AND each non-unit variant
10/// individually carries `#[non_exhaustive]` (protects future field additions
11/// inside variants).
12///
13/// # Examples
14///
15/// ```
16/// use rusty_pee::Error;
17///
18/// let e = Error::CompatibilityViolation("--capture not honored in Strict mode");
19/// assert_eq!(e.to_string(), "compatibility violation: --capture not honored in Strict mode");
20/// ```
21#[non_exhaustive]
22#[derive(thiserror::Error, Debug)]
23pub enum Error {
24    /// A Default-mode-only setting was passed to Strict mode (or vice versa).
25    /// Returned from `PeeBuilder::build()` only — before any IO occurs, so
26    /// no sinks are touched.
27    #[error("compatibility violation: {0}")]
28    CompatibilityViolation(&'static str),
29
30    /// The builder was configured into an impossible state (e.g., explicit
31    /// settings whose combination is logically invalid).
32    /// Returned from `PeeBuilder::build()` only.
33    #[error("invalid builder configuration: {0}")]
34    InvalidBuilderConfiguration(&'static str),
35
36    /// A sink's `write` failed mid-stream. Surfaced only when the builder
37    /// was configured with `ignore_write_errors(false)`. Carries the
38    /// registration index of the failing sink and the underlying io error.
39    ///
40    /// **Observable state**: surviving sinks have received the complete
41    /// current chunk in registration order (per FR-036). The failing sink
42    /// is dropped from the live-set.
43    #[error("sink {sink_index} write failed: {source}")]
44    #[non_exhaustive]
45    SinkWriteFailed {
46        sink_index: usize,
47        #[source]
48        source: std::io::Error,
49    },
50
51    /// An underlying IO error from the reader or process layer.
52    ///
53    /// **Observable state**: may leave sinks in a partially-written state
54    /// for the current chunk.
55    #[error("IO error: {0}")]
56    Io(#[from] std::io::Error),
57}