libscilo/config/
error.rs

1//! This module contains different kinds of errors that can be returned by library functions.
2
3use std::{io, path::PathBuf};
4
5/// Errors that can be raised during the parsing of a [`ConfigFile`][crate::ConfigFile].
6#[derive(Clone, Debug, thiserror::Error)]
7pub enum ConfigError {
8    /// The configuration file specified by the user cannot be found.
9    #[error("`{0}` does not exist.")]
10    DoesNotExist(PathBuf),
11
12    /// The configuration file specified by the user is not a file that can be parsed.
13    #[error("`{0}` is not a file.")]
14    NotAFile(PathBuf),
15
16    /// Parsing the user's configuration file failed for some reason.
17    #[error("Input error `{1}` while trying to read the contents of `{0}`.")]
18    IoError(PathBuf, io::ErrorKind),
19
20    /// Parsing the user's configuration file failed for some reason.
21    #[error("Could not parse the contents of `{0}`. {1}.")]
22    DeserializationError(PathBuf, String),
23
24    /// The regular expression written by the user is not a valid regular expression.
25    #[error(
26        "Regular expression `{value}` for `{name}` produced an error. Please check that this value is a valid regular expression. See https://docs.rs/regex/latest/regex/#examples for examples."
27    )]
28    RegexError { name: String, value: String },
29
30    /// The lint code written by the user does not match one of the variants of
31    /// [`LintCheck`][crate::lints::LintCheck].
32    #[error(
33        "Unknown lint type: `{0}`. Please double check the spelling, or consult the documentation for all the available lint codes."
34    )]
35    UnknownLintCode(String),
36}
37
38/// Errors that occur when attempting to normalize paths within the project directory.
39#[derive(Debug, thiserror::Error, Clone)]
40pub enum ProjectPathError {
41    #[error(
42        "Cannot canonicalize path `{0}`. Path does not exist or an internal component is not a directory. Please double-check that the path provided is correct."
43    )]
44    CanonicalizationError(PathBuf),
45
46    #[error("Path `{0}` is outside the project directory and does not need to be ignored.")]
47    PathNotWithinProject(PathBuf),
48
49    #[error(
50        "Ignored path `{0}` is a protected root directory. If you'd like to disable a root directory, set it to \"\" in the configuration file."
51    )]
52    IgnoringProtectedPath(PathBuf),
53}