Changed main function back to using anyhow::Result<T> cause i dont get backtraces without it

This commit is contained in:
Gvidas Juknevičius 2024-12-22 02:01:54 +02:00
parent d2b0e57ce6
commit b8728b8f8d
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB

View File

@ -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(())
} }