oxiforge 0.3.0

YAML-to-Rust code generator for oxivgl LVGL UIs
Documentation
// SPDX-License-Identifier: GPL-3.0-only
//! All error types returned by the oxiforge pipeline.
use thiserror::Error;

/// Errors produced by parsing, validation, or code generation.
#[derive(Debug, Error)]
pub enum OxiforgeError {
    /// Located validation error (file + line + column).
    #[error("{file}:{line}:{column}: {message}")]
    Validation {
        /// Source file path.
        file: String,
        /// 1-based line number.
        line: usize,
        /// 1-based column number.
        column: usize,
        /// Human-readable description.
        message: String,
    },

    /// YAML deserialization failure.
    #[error("YAML parse error: {source}")]
    Yaml {
        #[from]
        /// Underlying serde_yaml error.
        source: serde_yaml::Error,
    },

    /// File I/O error.
    #[error("IO error: {source}")]
    Io {
        #[from]
        /// Underlying I/O error.
        source: std::io::Error,
    },

    /// Catch-all for semantic/hint errors that don't have a source location.
    #[error("{0}")]
    Other(String),
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn error_displays_location() {
        let e = OxiforgeError::Validation {
            file: "ui.yaml".into(),
            line: 14,
            column: 5,
            message: "unknown widget type 'buttn'".into(),
        };
        let msg = e.to_string();
        assert!(msg.contains("ui.yaml:14:5"));
        assert!(msg.contains("buttn"));
    }
}