Switch from error_core to failure.

This commit is contained in:
Dan Gohman
2018-02-15 23:14:33 -08:00
parent e37f45667f
commit 6c9cf2bacf
11 changed files with 33 additions and 99 deletions

View File

@@ -1,21 +1,21 @@
use std::result;
use std::convert::From;
use std::error::Error as StdError;
use std::fmt;
use regex;
/// A result from the filecheck library.
pub type Result<T> = result::Result<T, Error>;
/// A filecheck error.
#[derive(Debug)]
#[derive(Fail, Debug)]
pub enum Error {
/// A syntax error in a check line.
#[fail(display = "{}", _0)]
Syntax(String),
/// A check refers to an undefined variable.
///
/// The pattern contains `$foo` where the `foo` variable has not yet been defined.
/// Use `$$` to match a literal dollar sign.
#[fail(display = "{}", _0)]
UndefVariable(String),
/// A pattern contains a back-reference to a variable that was defined in the same pattern.
///
@@ -26,40 +26,19 @@ pub enum Error {
/// check: Hello $(world=[^ ]*)
/// sameln: $world
/// ```
#[fail(display = "{}", _0)]
Backref(String),
/// A pattern contains multiple definitions of the same variable.
#[fail(display = "{}", _0)]
DuplicateDef(String),
/// An error in a regular expression.
///
/// Use `cause()` to get the underlying `Regex` library error.
Regex(regex::Error),
}
impl StdError for Error {
fn description(&self) -> &str {
use Error::*;
match *self {
Syntax(ref s) |
UndefVariable(ref s) |
Backref(ref s) |
DuplicateDef(ref s) => s,
Regex(ref err) => err.description(),
}
}
fn cause(&self) -> Option<&StdError> {
use Error::*;
match *self {
Regex(ref err) => Some(err),
_ => None,
}
}
}
impl fmt::Display for Error {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", self.description())
}
#[fail(display = "{}", _0)]
Regex(
#[cause]
regex::Error
),
}
impl From<regex::Error> for Error {

View File

@@ -243,6 +243,9 @@ pub use variable::{VariableMap, Value, NO_VARIABLES};
pub use checker::{Checker, CheckerBuilder};
extern crate regex;
extern crate failure;
#[macro_use]
extern crate failure_derive;
mod error;
mod variable;