codoc 0.1.0

Unified documentation parser for Ruby and TypeScript codebases
Documentation
//! Error types for the Codoc parser.

use std::path::PathBuf;
use thiserror::Error;

/// Result type alias for Codoc operations.
pub type Result<T> = std::result::Result<T, Error>;

/// Codoc error type.
#[derive(Error, Debug)]
pub enum Error {
    /// I/O error.
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),

    /// JSON serialization error.
    #[error("JSON error: {0}")]
    Json(#[from] serde_json::Error),

    /// Parse error.
    #[error("Parse error in {file}:{line}: {message}")]
    Parse {
        /// Source file path.
        file: PathBuf,
        /// Line number where the error occurred.
        line: u32,
        /// Error message.
        message: String,
    },

    /// Tree-sitter error.
    #[error("Tree-sitter error: {0}")]
    TreeSitter(String),

    /// Unsupported language.
    #[error("Unsupported language: {0}")]
    UnsupportedLanguage(String),

    /// File not found.
    #[error("File not found: {0}")]
    FileNotFound(PathBuf),

    /// Invalid configuration.
    #[error("Invalid configuration: {0}")]
    InvalidConfig(String),
}

impl Error {
    /// Creates a parse error.
    pub fn parse(file: impl Into<PathBuf>, line: u32, message: impl Into<String>) -> Self {
        Self::Parse {
            file: file.into(),
            line,
            message: message.into(),
        }
    }

    /// Creates a tree-sitter error.
    pub fn tree_sitter(message: impl Into<String>) -> Self {
        Self::TreeSitter(message.into())
    }
}