From f7155436e417fd5c1517fc8a856a02ec7f01a56d Mon Sep 17 00:00:00 2001 From: marcelarie Date: Fri, 18 Oct 2024 19:30:30 +0200 Subject: [PATCH] fix: Show error message when readign directories for now --- src/main.rs | 5 ++++- src/syntax_tree/alias.rs | 1 - src/syntax_tree/process_file.rs | 33 +++++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 82aeffd..6afc262 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,10 @@ mod syntax_tree; use command::arguments::CliArgs; use config::alias_ignore::{self, AliasIgnoreResult}; use output::writer::process_and_write_aliases; -use std::{collections::HashSet, path::{Path, PathBuf}}; +use std::{ + collections::HashSet, + path::{Path, PathBuf}, +}; use syntax_tree::process_file::process_path; fn main() { diff --git a/src/syntax_tree/alias.rs b/src/syntax_tree/alias.rs index be2d205..85fd01e 100644 --- a/src/syntax_tree/alias.rs +++ b/src/syntax_tree/alias.rs @@ -188,7 +188,6 @@ pub fn find_aliases( // } // ); // } - alias.is_valid_nushell = validate_result.is_valid; alias.error_messages = validate_result.error_messages; }); diff --git a/src/syntax_tree/process_file.rs b/src/syntax_tree/process_file.rs index 50bd1d7..69560fc 100644 --- a/src/syntax_tree/process_file.rs +++ b/src/syntax_tree/process_file.rs @@ -1,3 +1,4 @@ +use crate::command::arguments::DEBUG_MODE_GLOBAL; use crate::syntax_tree::alias::Alias; use std::cell::RefCell; use std::rc::Rc; @@ -17,15 +18,25 @@ pub fn process_file( parser: Rc>, file_path: PathBuf, ) -> Vec { - let code = fs::read_to_string(file_path).expect("Error reading file"); - - let mut parser = parser.borrow_mut(); - - let tree = parser.parse(&code, None).expect("Error parsing code"); - - let mut cursor = tree.walk(); - - find_aliases(&mut cursor, code.as_bytes()) + match fs::read_to_string(&file_path) { + Ok(code) => { + let mut parser = parser.borrow_mut(); + let tree = parser.parse(&code, None).expect("Error parsing code"); + let mut cursor = tree.walk(); + find_aliases(&mut cursor, code.as_bytes()) + } + Err(e) => { + let should_debug = *DEBUG_MODE_GLOBAL.get().unwrap_or(&false); + if should_debug { + eprintln!( + "ERROR_READING({}): {:?}", + file_path.display().to_string(), + e + ); + } + Vec::new() + } + } } /// Processes all files in a directory to extract aliases. @@ -72,7 +83,9 @@ pub fn process_path(file_path: PathBuf) -> Vec { let parser = Rc::new(RefCell::new(parser)); if file_path.is_dir() { - process_dir(parser, file_path) + println!("Error: Can't process directories yet."); + std::process::exit(1); + // process_dir(parser, file_path) } else { process_file(parser, file_path) }