herolib_code/parser/
error.rs

1//! Error types for the parser module.
2//!
3//! This module defines custom error types for handling parsing and file system errors.
4
5use std::path::PathBuf;
6use thiserror::Error;
7
8/// Errors that can occur during code parsing.
9#[derive(Debug, Error)]
10pub enum ParseError {
11    /// Failed to read a file.
12    #[error("Failed to read file '{path}': {source}")]
13    FileRead {
14        /// The path of the file that couldn't be read.
15        path: PathBuf,
16        /// The underlying IO error.
17        #[source]
18        source: std::io::Error,
19    },
20
21    /// Failed to parse Rust source code.
22    #[error("Failed to parse Rust source in '{path}': {message}")]
23    SyntaxError {
24        /// The path of the file with the syntax error.
25        path: PathBuf,
26        /// Error message from the parser.
27        message: String,
28    },
29
30    /// The specified directory does not exist.
31    #[error("Directory does not exist: {0}")]
32    DirectoryNotFound(PathBuf),
33
34    /// Failed to walk directory.
35    #[error("Failed to walk directory '{path}': {source}")]
36    WalkError {
37        /// The path of the directory being walked.
38        path: PathBuf,
39        /// The underlying walkdir error.
40        #[source]
41        source: walkdir::Error,
42    },
43
44    /// Invalid path encoding.
45    #[error("Invalid path encoding: {0}")]
46    InvalidPath(PathBuf),
47}
48
49/// Result type alias for parser operations.
50pub type ParseResult<T> = Result<T, ParseError>;