2 use std::fmt::{self, Formatter};
3 use std::path::{Path, PathBuf};
5 use crate::docfs::PathError;
13 impl error::Error for Error {}
15 impl std::fmt::Display for Error {
16 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
17 let file = self.file.display().to_string();
19 write!(f, "{}", self.error)
21 write!(f, "\"{}\": {}", self.file.display(), self.error)
26 impl PathError for Error {
27 fn new<S, P: AsRef<Path>>(e: S, path: P) -> Error
31 Error { file: path.as_ref().to_path_buf(), error: e.to_string() }
36 macro_rules! try_none {
37 ($e:expr, $file:expr) => {{
42 return Err(<crate::error::Error as crate::docfs::PathError>::new(
43 io::Error::new(io::ErrorKind::Other, "not found"),
52 macro_rules! try_err {
53 ($e:expr, $file:expr) => {{
56 Err(e) => return Err(Error::new(e, $file)),