Skip to content

Commit

Permalink
fix(main.rs): Handle file not found error
Browse files Browse the repository at this point in the history
- Print an error message and exit with code 1 if the file is not found
- Validate file extension and print an error message if it does not have the .xlsx extension
  • Loading branch information
sangshuduo committed Nov 30, 2024
1 parent 275298b commit d008390
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cat_xlsx/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ fn main() -> Result<(), Box<dyn Error>> {
let path = args.xlsx_file;
// Check if the file exists
if !path.exists() {
eprintln!("Error: File not found");
std::process::exit(1);
}
// Validate file extension
if !path.extension().map_or(false, |ext| ext.eq_ignore_ascii_case("xlsx")) {
if !path
.extension()
.map_or(false, |ext| ext.eq_ignore_ascii_case("xlsx"))
{
eprintln!("Error: File must have .xlsx extension");
std::process::exit(1);
}
Expand Down

0 comments on commit d008390

Please sign in to comment.