diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-01-07 09:53:14 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-01-07 09:53:14 +0200 |
commit | c73b09c7d378d83ae47fc5951beb3f154c881604 (patch) | |
tree | dd10c66150391e76a5164a6e1c17c4edb2311f3f | |
parent | 8ea91c0c154ea3ed81e7a40a233a82a82a9a2f5f (diff) | |
download | riki-c73b09c7d378d83ae47fc5951beb3f154c881604.tar.gz |
refactor: move WalkDir error to src/srcdir.rs
Sponsored-by: author
-rw-r--r-- | src/error.rs | 4 | ||||
-rw-r--r-- | src/srcdir.rs | 11 |
2 files changed, 10 insertions, 5 deletions
diff --git a/src/error.rs b/src/error.rs index 8105aa8..6bc0c1d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,8 +3,8 @@ use std::path::PathBuf; #[derive(Debug, thiserror::Error)] pub enum SiteError { - #[error("failed to list files in source directory: {0}")] - WalkDir(PathBuf, #[source] walkdir::Error), + #[error(transparent)] + WalkDir(#[from] crate::srcdir::SourceDirError), #[error("could not read file: {0}")] FileRead(PathBuf, #[source] std::io::Error), diff --git a/src/srcdir.rs b/src/srcdir.rs index 66d2a04..b1a9317 100644 --- a/src/srcdir.rs +++ b/src/srcdir.rs @@ -1,8 +1,13 @@ -use crate::error::SiteError; use log::trace; use std::path::{Path, PathBuf}; use walkdir::WalkDir; +#[derive(Debug, thiserror::Error)] +pub enum SourceDirError { + #[error("failed to list files in source directory: {0}")] + WalkDir(PathBuf, #[source] walkdir::Error), +} + pub struct SourceDir { path: PathBuf, files: Vec<PathBuf>, @@ -31,13 +36,13 @@ impl SourceDir { self.files.push(path.into()); } - pub fn scan(&mut self) -> Result<(), SiteError> { + pub fn scan(&mut self) -> Result<(), SourceDirError> { if self.artificial { trace!("SourceDir::scan: artificial mode, not actually scanning"); } else { trace!("SourceDir::scan: find files in {}", self.path.display()); for e in WalkDir::new(&self.path) { - let e = e.map_err(|err| SiteError::WalkDir(self.path.clone(), err))?; + let e = e.map_err(|err| SourceDirError::WalkDir(self.path.clone(), err))?; let path = e.path(); trace!("SourceDir::scan: found {}", path.display()); self.insert(path); |