Skip to content

Commit

Permalink
feat: handle directory not found and file errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Rickard Natt och Dag committed May 4, 2023
1 parent daef2a7 commit 65ae7f4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut filtered_files = 0;
let mut todos: Vec<Todo> = vec![];

// Check if the path is a directory
match fs::metadata(&path) {
Err(err) => {
let error = match err.kind() {
std::io::ErrorKind::NotFound => format!("Directory not found: {path}").into(),
error => todo!("Error: {error}"),
};

return Err(error);
}
Ok(_) => {
if !fs::metadata(&path)?.is_dir() {
return Err("Path is not a directory".into());
}
}
}

let supported_filetypes = vec!["ts", "js", "tsx", "jsx", "vue", "html", "scss"];
let gitignore = fs::read_to_string(".gitignore")?;
let gitignore = gitignore
Expand Down

0 comments on commit 65ae7f4

Please sign in to comment.