mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-06-25 14:22:54 +02:00
progress
This commit is contained in:
@ -4,6 +4,7 @@ extern crate regex_syntax as syntax;
|
||||
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
use std::result;
|
||||
|
||||
pub use search::{Grep, GrepBuilder};
|
||||
@ -26,6 +27,13 @@ pub enum Error {
|
||||
/// pattern. For example, if the line terminator is `\n` and the regex
|
||||
/// pattern is `\w+\n\w+`, then the presence of `\n` will cause this error.
|
||||
LiteralNotAllowed(char),
|
||||
/// This errors occurs when a line exceeds the buffer size. The buffer
|
||||
/// size is given.
|
||||
LineTooLong(usize),
|
||||
/// An IO error occurred while searching.
|
||||
Io(io::Error),
|
||||
/// An unused enum variant that indicates this enum may be expanded in
|
||||
/// the future and therefore should not be exhaustively matched.
|
||||
#[doc(hidden)]
|
||||
__Nonexhaustive,
|
||||
}
|
||||
@ -35,6 +43,8 @@ impl error::Error for Error {
|
||||
match *self {
|
||||
Error::Regex(ref err) => err.description(),
|
||||
Error::LiteralNotAllowed(_) => "use of forbidden literal",
|
||||
Error::LineTooLong(_) => "line exceeds buffer size",
|
||||
Error::Io(ref err) => err.description(),
|
||||
Error::__Nonexhaustive => unreachable!(),
|
||||
}
|
||||
}
|
||||
@ -42,6 +52,7 @@ impl error::Error for Error {
|
||||
fn cause(&self) -> Option<&error::Error> {
|
||||
match *self {
|
||||
Error::Regex(ref err) => err.cause(),
|
||||
Error::Io(ref err) => err.cause(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -54,6 +65,11 @@ impl fmt::Display for Error {
|
||||
Error::LiteralNotAllowed(chr) => {
|
||||
write!(f, "Literal '{}' not allowed.", chr)
|
||||
}
|
||||
Error::LineTooLong(limit) => {
|
||||
write!(f, "Line exceeded buffer size of {} bytes, try \
|
||||
searching with memory maps instead.", limit)
|
||||
}
|
||||
Error::Io(ref err) => err.fmt(f),
|
||||
Error::__Nonexhaustive => unreachable!(),
|
||||
}
|
||||
}
|
||||
@ -70,3 +86,9 @@ impl From<syntax::Error> for Error {
|
||||
Error::Regex(regex::Error::Syntax(err))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(err: io::Error) -> Error {
|
||||
Error::Io(err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user