Skip to main content

convention_lint/
error.rs

1//! Error types for `convention-lint`.
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// All errors that `convention-lint` can produce.
7///
8/// This type is `#[non_exhaustive]` so that new variants can be added in
9/// minor versions without breaking downstream `match` expressions.
10#[derive(Debug, Error)]
11#[non_exhaustive]
12pub enum Error {
13    /// The manifest file could not be opened or read.
14    #[error("cannot read `{path}`: {source}")]
15    Io {
16        /// Path to the manifest that could not be read.
17        path: PathBuf,
18        /// Underlying I/O error.
19        #[source]
20        source: std::io::Error,
21    },
22
23    /// The `dirs` list in a check rule is empty.
24    #[error("the `dirs` list in a convention-lint check cannot be empty")]
25    EmptyDirs,
26
27    /// The manifest file contains invalid TOML.
28    #[error("cannot parse `{path}`: {source}")]
29    Toml {
30        /// Path to the manifest that could not be parsed.
31        path: PathBuf,
32        /// Underlying TOML parse error.
33        #[source]
34        source: toml::de::Error,
35    },
36
37    /// The `[workspace.metadata.convention-lint]` or `[package.metadata.convention-lint]` section is absent from the manifest.
38    #[error(
39        "`[workspace.metadata.convention-lint]` or `[package.metadata.convention-lint]` section not found in `{0}`"
40    )]
41    MissingSection(PathBuf),
42
43    /// The metadata section exists but is not a TOML table.
44    #[error(
45        "`[workspace.metadata.convention-lint]` or `[package.metadata.convention-lint]` must be a TOML table"
46    )]
47    InvalidSection,
48
49    /// The convention string is not one of the recognised identifiers.
50    #[error(
51        "unknown convention `{value}` for pattern(s) [{context}]; \
52         valid values: `snake_case`, `CamelCase`, `camelCase`, \
53         `SCREAMING_SNAKE_CASE`, `kebab-case`"
54    )]
55    UnknownConvention {
56        /// The file extensions (e.g. `*.idl`) that the unrecognised convention was configured for.
57        context: String,
58        /// The unrecognised convention string supplied by the user.
59        value: String,
60    },
61}