Skip to content

Commit

Permalink
fix: Show error message when readign directories for now
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelarie committed Oct 18, 2024
1 parent 2944e2e commit f715543
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion src/syntax_tree/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ pub fn find_aliases(
// }
// );
// }

alias.is_valid_nushell = validate_result.is_valid;
alias.error_messages = validate_result.error_messages;
});
Expand Down
33 changes: 23 additions & 10 deletions src/syntax_tree/process_file.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,15 +18,25 @@ pub fn process_file(
parser: Rc<RefCell<Parser>>,
file_path: PathBuf,
) -> Vec<Alias> {
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.
Expand Down Expand Up @@ -72,7 +83,9 @@ pub fn process_path(file_path: PathBuf) -> Vec<Alias> {
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)
}
Expand Down

0 comments on commit f715543

Please sign in to comment.