Changed main function back to using anyhow::Result<T> cause i dont get backtraces without it
This commit is contained in:
parent
d2b0e57ce6
commit
b8728b8f8d
21
src/main.rs
21
src/main.rs
|
@ -7,7 +7,7 @@ mod logger;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> anyhow::Result<()> {
|
||||||
let cli = mclangc::cli::CliArgs::parse();
|
let cli = mclangc::cli::CliArgs::parse();
|
||||||
cli.set_log_level();
|
cli.set_log_level();
|
||||||
cli.validate();
|
cli.validate();
|
||||||
|
@ -15,25 +15,16 @@ fn main() -> ExitCode {
|
||||||
let fp = PathBuf::from(file);
|
let fp = PathBuf::from(file);
|
||||||
if !fp.exists() {
|
if !fp.exists() {
|
||||||
error!("File {fp:?} doesnt exits, exiting");
|
error!("File {fp:?} doesnt exits, exiting");
|
||||||
return ExitCode::FAILURE;
|
anyhow::bail!("")
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = std::fs::read_to_string(fp).unwrap();
|
let data = std::fs::read_to_string(fp).unwrap();
|
||||||
info!("Tokenising {file}");
|
info!("Tokenising {file}");
|
||||||
let Ok(tokens) = mclangc::tokeniser::tokenise(&data, &file) else {
|
let tokens = mclangc::tokeniser::tokenise(&data, &file)?;
|
||||||
error!("Failed to tokenise file, exiting");
|
|
||||||
return ExitCode::FAILURE;
|
|
||||||
};
|
|
||||||
info!("Parsing {file}");
|
info!("Parsing {file}");
|
||||||
let Ok(prog) = mclangc::parser::parse_program(tokens) else {
|
let mut prog = mclangc::parser::parse_program(tokens)?;
|
||||||
error!("Failed to parse file, exiting");
|
|
||||||
return ExitCode::FAILURE;
|
|
||||||
};
|
|
||||||
info!("Validating {file}");
|
info!("Validating {file}");
|
||||||
let Ok(validated) = mclangc::validator::validate_code(&prog) else {
|
let validated = mclangc::validator::validate_code(&mut prog)?;
|
||||||
error!("Failed to validate file, exiting");
|
|
||||||
return ExitCode::FAILURE;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
ExitCode::SUCCESS
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user