Skip to main content

tenshift_core/
error.rs

1//! Error types for tenshift.
2//!
3//! Every error is actionable and carries context. No generic "something went wrong."
4//!
5//! All error variants include a "Fix:" suggestion that provides immediate
6//! actionable guidance for resolving the issue.
7
8use std::path::PathBuf;
9
10/// All errors that can occur in the pipeline.
11///
12/// Note: This enum is `#[non_exhaustive]` because the pipeline architecture
13/// is designed to be extensible. We anticipate adding new variants in the future
14/// as we introduce new hardware integrations and data processing stages.
15#[non_exhaustive]
16#[derive(Debug, Clone, thiserror::Error)]
17pub enum Error {
18    /// A source failed to initialize or advance safely.
19    #[error("source '{source_name}' failed: {reason}. Fix: inspect the source implementation and input boundary for panics, stalls, or invalid reads.")]
20    SourceFailed {
21        /// The source name.
22        source_name: String,
23        /// What went wrong.
24        reason: String,
25    },
26
27    /// A source file could not be read.
28    #[error("failed to read {path}: {reason}. Fix: verify the path exists and is readable.")]
29    ReadFailed {
30        /// The path that failed.
31        path: PathBuf,
32        /// Why it failed.
33        reason: String,
34    },
35
36    /// A source file was corrupt or unparseable.
37    #[error("corrupt data in {path}: {reason}. Fix: repair or remove the malformed input.")]
38    CorruptData {
39        /// The path containing corrupt data.
40        path: PathBuf,
41        /// What went wrong.
42        reason: String,
43    },
44
45    /// No files matched the source pattern.
46    #[error("no files matched pattern: {pattern}. Fix: point the source at at least one existing input file.")]
47    EmptySource {
48        /// The glob pattern that matched nothing.
49        pattern: String,
50    },
51
52    /// The pipeline was shut down (Ctrl+C or explicit stop).
53    #[error("pipeline shut down")]
54    Shutdown,
55
56    /// A user-provided transform function failed.
57    #[error("transform failed on item {index}: {reason}. Fix: inspect the transform input and handle that case explicitly.")]
58    TransformFailed {
59        /// Which item in the stream caused the failure.
60        index: u64,
61        /// What went wrong.
62        reason: String,
63    },
64
65    /// Collation of a batch failed.
66    #[error("collation failed: {reason}. Fix: ensure each sample in the batch has the same required fields, dtype, and shape.")]
67    CollateFailed {
68        /// What went wrong.
69        reason: String,
70    },
71
72    /// An I/O error occurred.
73    #[error("i/o error: {0}. Fix: resolve the underlying operating system error and retry.")]
74    Io(std::sync::Arc<std::io::Error>),
75
76    /// A glob pattern was invalid.
77    #[error("invalid glob pattern: {0}. Fix: provide a valid glob expression.")]
78    InvalidPattern(String),
79
80    /// Pipeline configuration was invalid.
81    #[error(
82        "invalid config: {reason}. Fix: update the pipeline configuration to a supported value."
83    )]
84    InvalidConfig {
85        /// What was wrong.
86        reason: String,
87    },
88}
89
90impl From<std::io::Error> for Error {
91    fn from(e: std::io::Error) -> Self {
92        Error::Io(std::sync::Arc::new(e))
93    }
94}
95
96impl From<glob::PatternError> for Error {
97    fn from(e: glob::PatternError) -> Self {
98        Error::InvalidPattern(e.to_string())
99    }
100}
101
102/// Convenience result type.
103pub type Result<T> = std::result::Result<T, Error>;