Skip to main content

filecheck/
error.rs

1use std::result;
2use thiserror::Error;
3
4/// A result from the filecheck library.
5pub type Result<T> = result::Result<T, Error>;
6
7/// A filecheck error.
8#[derive(Error, Debug)]
9pub enum Error {
10    /// A syntax error in a check line.
11    #[error("{0}")]
12    Syntax(String),
13    /// A check refers to an undefined variable.
14    ///
15    /// The pattern contains `$foo` where the `foo` variable has not yet been defined.
16    /// Use `$$` to match a literal dollar sign.
17    #[error("{0}")]
18    UndefVariable(String),
19    /// A pattern contains a back-reference to a variable that was defined in the same pattern.
20    ///
21    /// For example, `check: Hello $(world=.*) $world`. Backreferences are not supported. Often the
22    /// desired effect can be achieved with the `sameln` check:
23    ///
24    /// ```text
25    /// check: Hello $(world=[^ ]*)
26    /// sameln: $world
27    /// ```
28    #[error("{0}")]
29    Backref(String),
30    /// A pattern contains multiple definitions of the same variable.
31    #[error("{0}")]
32    DuplicateDef(String),
33    /// An error in a regular expression.
34    ///
35    /// Use `cause()` to get the underlying `Regex` library error.
36    #[error("{0}")]
37    Regex(#[from] regex::Error),
38}