Skip to main content

bito_lint_core/
error.rs

1//! Error types for bito-lint-core.
2
3use camino::Utf8PathBuf;
4use thiserror::Error;
5
6/// Errors that can occur when working with configuration.
7#[derive(Error, Debug)]
8pub enum ConfigError {
9    /// Failed to deserialize configuration.
10    #[error("invalid configuration: {0}")]
11    Deserialize(#[from] Box<figment::Error>),
12
13    /// Configuration file not found after searching all locations.
14    #[error("no configuration file found")]
15    NotFound,
16
17    /// A custom entry references a file that cannot be read.
18    #[error("custom entry file not found: {path}: {source}")]
19    CustomEntryFile {
20        /// The resolved file path that could not be read.
21        path: Utf8PathBuf,
22        /// The underlying I/O error.
23        source: std::io::Error,
24    },
25
26    /// A custom entry has neither `instructions` nor `file`.
27    #[error("custom entry has neither 'instructions' nor 'file'")]
28    CustomEntryEmpty,
29}
30
31/// Result type alias using [`ConfigError`].
32pub type ConfigResult<T> = Result<T, ConfigError>;
33
34/// Errors that can occur during text analysis.
35#[derive(Error, Debug)]
36pub enum AnalysisError {
37    /// The tokenizer could not be initialized.
38    #[error("tokenizer initialization failed: {0}")]
39    TokenizerInit(String),
40
41    /// The input text is empty or has no scorable content.
42    #[error("no scorable text in input")]
43    EmptyInput,
44
45    /// An unknown template name was provided.
46    #[error("unknown template: {name}. Use: {available}")]
47    UnknownTemplate {
48        /// The template name that was requested.
49        name: String,
50        /// Comma-separated list of available template names.
51        available: String,
52    },
53
54    /// One or more unknown check names were provided.
55    #[error("unknown check(s): {names}. Available: {available}")]
56    UnknownCheck {
57        /// Comma-separated list of unrecognised check names.
58        names: String,
59        /// Comma-separated list of valid check names.
60        available: String,
61    },
62
63    /// The input exceeds the configured maximum size.
64    #[error("input too large: {size} bytes exceeds limit of {max} bytes")]
65    InputTooLarge {
66        /// Actual size of the input in bytes.
67        size: usize,
68        /// Configured maximum size in bytes.
69        max: usize,
70    },
71
72    /// A rule specifies conflicting configuration options.
73    #[error("conflicting rule config: {0}")]
74    ConflictingConfig(String),
75}
76
77/// Result type alias using [`AnalysisError`].
78pub type AnalysisResult<T> = Result<T, AnalysisError>;