Skip to main content

rustloclib/
error.rs

1//! Error types for rustloclib
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// Errors that can occur during LOC counting
7#[derive(Error, Debug)]
8pub enum RustlocError {
9    /// Failed to read a file
10    #[error("failed to read file '{path}': {source}")]
11    FileRead {
12        path: PathBuf,
13        source: std::io::Error,
14    },
15
16    /// Failed to parse Cargo.toml or workspace metadata
17    #[error("failed to parse cargo metadata: {0}")]
18    CargoMetadata(String),
19
20    /// Invalid glob pattern
21    #[error("invalid glob pattern '{pattern}': {message}")]
22    InvalidGlob { pattern: String, message: String },
23
24    /// Path does not exist
25    #[error("path does not exist: {0}")]
26    PathNotFound(PathBuf),
27
28    /// No Cargo.toml found at or above path
29    #[error("no Cargo.toml found at or above: {0}")]
30    CargoTomlNotFound(PathBuf),
31
32    /// Source file is not supported by any registered backend.
33    #[error("unsupported source file: {0}")]
34    UnsupportedSourceFile(PathBuf),
35
36    /// Not a Rust file.
37    #[deprecated(note = "use UnsupportedSourceFile instead")]
38    #[error("not a Rust file: {0}")]
39    NotRustFile(PathBuf),
40
41    /// IO error
42    #[error("IO error: {0}")]
43    Io(#[from] std::io::Error),
44
45    /// Git operation error
46    #[error("git error: {0}")]
47    GitError(String),
48}