Skip to main content

specta_swift/
error.rs

1//! Error types for the Swift language exporter.
2
3use thiserror::Error;
4
5/// Errors that can occur during Swift code generation.
6#[derive(Debug, Error)]
7pub enum Error {
8    /// Swift does not support this type.
9    #[error("Unsupported type: {0}")]
10    UnsupportedType(String),
11
12    /// Invalid identifier for Swift.
13    #[error("Invalid identifier: {0}")]
14    InvalidIdentifier(String),
15
16    /// Circular reference detected in type definitions.
17    #[error("Circular reference detected")]
18    CircularReference,
19
20    /// Generic constraint error.
21    #[error("Generic constraint error: {0}")]
22    GenericConstraint(String),
23
24    /// IO error during file operations.
25    #[error("IO error: {0}")]
26    Io(#[from] std::io::Error),
27
28    /// Invalid configuration.
29    #[error("Configuration error: {0}")]
30    Configuration(String),
31
32    /// Custom format callback failed.
33    #[error("Format error: {message}: {source}")]
34    Format {
35        /// Context describing which format callback failed.
36        message: &'static str,
37        /// The underlying format error.
38        source: specta::FormatError,
39    },
40}
41
42impl Error {
43    pub(crate) fn format(message: &'static str, source: specta::FormatError) -> Self {
44        Self::Format { message, source }
45    }
46}