mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-05-19 09:40:22 -07:00
ignore: allow use of Error::description
We can remove it in the next semver incompatible release.
This commit is contained in:
parent
41695c66fa
commit
9cb93abd11
@ -69,8 +69,8 @@ pub use walk::{DirEntry, Walk, WalkBuilder, WalkParallel, WalkState};
|
|||||||
|
|
||||||
mod dir;
|
mod dir;
|
||||||
pub mod gitignore;
|
pub mod gitignore;
|
||||||
mod pathutil;
|
|
||||||
pub mod overrides;
|
pub mod overrides;
|
||||||
|
mod pathutil;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
mod walk;
|
mod walk;
|
||||||
|
|
||||||
@ -134,35 +134,34 @@ impl Clone for Error {
|
|||||||
fn clone(&self) -> Error {
|
fn clone(&self) -> Error {
|
||||||
match *self {
|
match *self {
|
||||||
Error::Partial(ref errs) => Error::Partial(errs.clone()),
|
Error::Partial(ref errs) => Error::Partial(errs.clone()),
|
||||||
Error::WithLineNumber { line, ref err } => {
|
Error::WithLineNumber { line, ref err } => Error::WithLineNumber {
|
||||||
Error::WithLineNumber { line: line, err: err.clone() }
|
line: line,
|
||||||
}
|
err: err.clone(),
|
||||||
Error::WithPath { ref path, ref err } => {
|
},
|
||||||
Error::WithPath { path: path.clone(), err: err.clone() }
|
Error::WithPath { ref path, ref err } => Error::WithPath {
|
||||||
}
|
path: path.clone(),
|
||||||
Error::WithDepth { depth, ref err } => {
|
err: err.clone(),
|
||||||
Error::WithDepth { depth: depth, err: err.clone() }
|
},
|
||||||
}
|
Error::WithDepth { depth, ref err } => Error::WithDepth {
|
||||||
Error::Loop { ref ancestor, ref child } => {
|
depth: depth,
|
||||||
Error::Loop {
|
err: err.clone(),
|
||||||
ancestor: ancestor.clone(),
|
},
|
||||||
child: child.clone()
|
Error::Loop {
|
||||||
}
|
ref ancestor,
|
||||||
}
|
ref child,
|
||||||
Error::Io(ref err) => {
|
} => Error::Loop {
|
||||||
match err.raw_os_error() {
|
ancestor: ancestor.clone(),
|
||||||
Some(e) => Error::Io(io::Error::from_raw_os_error(e)),
|
child: child.clone(),
|
||||||
None => {
|
},
|
||||||
Error::Io(io::Error::new(err.kind(), err.to_string()))
|
Error::Io(ref err) => match err.raw_os_error() {
|
||||||
}
|
Some(e) => Error::Io(io::Error::from_raw_os_error(e)),
|
||||||
}
|
None => Error::Io(io::Error::new(err.kind(), err.to_string())),
|
||||||
}
|
},
|
||||||
Error::Glob { ref glob, ref err } => {
|
Error::Glob { ref glob, ref err } => Error::Glob {
|
||||||
Error::Glob { glob: glob.clone(), err: err.clone() }
|
glob: glob.clone(),
|
||||||
}
|
err: err.clone(),
|
||||||
Error::UnrecognizedFileType(ref err) => {
|
},
|
||||||
Error::UnrecognizedFileType(err.clone())
|
Error::UnrecognizedFileType(ref err) => Error::UnrecognizedFileType(err.clone()),
|
||||||
}
|
|
||||||
Error::InvalidDefinition => Error::InvalidDefinition,
|
Error::InvalidDefinition => Error::InvalidDefinition,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -263,6 +262,7 @@ impl Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl error::Error for Error {
|
impl error::Error for Error {
|
||||||
|
#[allow(deprecated)]
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
match *self {
|
match *self {
|
||||||
Error::Partial(_) => "partial error",
|
Error::Partial(_) => "partial error",
|
||||||
@ -282,34 +282,37 @@ impl fmt::Display for Error {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
Error::Partial(ref errs) => {
|
Error::Partial(ref errs) => {
|
||||||
let msgs: Vec<String> =
|
let msgs: Vec<String> = errs.iter().map(|err| err.to_string()).collect();
|
||||||
errs.iter().map(|err| err.to_string()).collect();
|
|
||||||
write!(f, "{}", msgs.join("\n"))
|
write!(f, "{}", msgs.join("\n"))
|
||||||
}
|
}
|
||||||
Error::WithLineNumber { line, ref err } => {
|
Error::WithLineNumber { line, ref err } => write!(f, "line {}: {}", line, err),
|
||||||
write!(f, "line {}: {}", line, err)
|
Error::WithPath { ref path, ref err } => write!(f, "{}: {}", path.display(), err),
|
||||||
}
|
|
||||||
Error::WithPath { ref path, ref err } => {
|
|
||||||
write!(f, "{}: {}", path.display(), err)
|
|
||||||
}
|
|
||||||
Error::WithDepth { ref err, .. } => err.fmt(f),
|
Error::WithDepth { ref err, .. } => err.fmt(f),
|
||||||
Error::Loop { ref ancestor, ref child } => {
|
Error::Loop {
|
||||||
write!(f, "File system loop found: \
|
ref ancestor,
|
||||||
|
ref child,
|
||||||
|
} => write!(
|
||||||
|
f,
|
||||||
|
"File system loop found: \
|
||||||
{} points to an ancestor {}",
|
{} points to an ancestor {}",
|
||||||
child.display(), ancestor.display())
|
child.display(),
|
||||||
}
|
ancestor.display()
|
||||||
|
),
|
||||||
Error::Io(ref err) => err.fmt(f),
|
Error::Io(ref err) => err.fmt(f),
|
||||||
Error::Glob { glob: None, ref err } => write!(f, "{}", err),
|
Error::Glob {
|
||||||
Error::Glob { glob: Some(ref glob), ref err } => {
|
glob: None,
|
||||||
write!(f, "error parsing glob '{}': {}", glob, err)
|
ref err,
|
||||||
}
|
} => write!(f, "{}", err),
|
||||||
Error::UnrecognizedFileType(ref ty) => {
|
Error::Glob {
|
||||||
write!(f, "unrecognized file type: {}", ty)
|
glob: Some(ref glob),
|
||||||
}
|
ref err,
|
||||||
Error::InvalidDefinition => {
|
} => write!(f, "error parsing glob '{}': {}", glob, err),
|
||||||
write!(f, "invalid definition (format is type:glob, e.g., \
|
Error::UnrecognizedFileType(ref ty) => write!(f, "unrecognized file type: {}", ty),
|
||||||
html:*.html)")
|
Error::InvalidDefinition => write!(
|
||||||
}
|
f,
|
||||||
|
"invalid definition (format is type:glob, e.g., \
|
||||||
|
html:*.html)"
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -450,8 +453,7 @@ mod tests {
|
|||||||
use std::result;
|
use std::result;
|
||||||
|
|
||||||
/// A convenient result type alias.
|
/// A convenient result type alias.
|
||||||
pub type Result<T> =
|
pub type Result<T> = result::Result<T, Box<dyn error::Error + Send + Sync>>;
|
||||||
result::Result<T, Box<dyn error::Error + Send + Sync>>;
|
|
||||||
|
|
||||||
macro_rules! err {
|
macro_rules! err {
|
||||||
($($tt:tt)*) => {
|
($($tt:tt)*) => {
|
||||||
@ -489,9 +491,8 @@ mod tests {
|
|||||||
if path.is_dir() {
|
if path.is_dir() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fs::create_dir_all(&path).map_err(|e| {
|
fs::create_dir_all(&path)
|
||||||
err!("failed to create {}: {}", path.display(), e)
|
.map_err(|e| err!("failed to create {}: {}", path.display(), e))?;
|
||||||
})?;
|
|
||||||
return Ok(TempDir(path));
|
return Ok(TempDir(path));
|
||||||
}
|
}
|
||||||
Err(err!("failed to create temp dir after {} tries", TRIES))
|
Err(err!("failed to create temp dir after {} tries", TRIES))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user