herolib-code 0.3.13

Code analysis and parsing utilities for Rust source files
Documentation
//! Error types for the parser module.
//!
//! This module defines custom error types for handling parsing and file system errors.

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

/// Errors that can occur during code parsing.
#[derive(Debug, Error)]
pub enum ParseError {
    /// Failed to read a file.
    #[error("Failed to read file '{path}': {source}")]
    FileRead {
        /// The path of the file that couldn't be read.
        path: PathBuf,
        /// The underlying IO error.
        #[source]
        source: std::io::Error,
    },

    /// Failed to parse Rust source code.
    #[error("Failed to parse Rust source in '{path}': {message}")]
    SyntaxError {
        /// The path of the file with the syntax error.
        path: PathBuf,
        /// Error message from the parser.
        message: String,
    },

    /// The specified directory does not exist.
    #[error("Directory does not exist: {0}")]
    DirectoryNotFound(PathBuf),

    /// Failed to walk directory.
    #[error("Failed to walk directory '{path}': {source}")]
    WalkError {
        /// The path of the directory being walked.
        path: PathBuf,
        /// The underlying walkdir error.
        #[source]
        source: walkdir::Error,
    },

    /// Invalid path encoding.
    #[error("Invalid path encoding: {0}")]
    InvalidPath(PathBuf),
}

/// Result type alias for parser operations.
pub type ParseResult<T> = Result<T, ParseError>;