Skip to content

Commit

Permalink
handling error returning from run method
Browse files Browse the repository at this point in the history
  • Loading branch information
dhanushrajgp committed Jul 6, 2024
1 parent 091679f commit cfc15b0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use std::error::Error;
use std::fs;
use std::process;

Expand All @@ -14,13 +15,16 @@ fn main() {
println!("Searching for {}", config.query);
println!("In file {}", config.file_path);

run(config);
if let Err(e) = run(config) {
println!("Application error: {e}");
process::exit(1)
}
}

fn run(config: Config) {
let content =
fs::read_to_string(config.file_path).expect("should have been able to read the file");
fn run(config: Config) -> Result<(), Box<dyn Error>> {
let content = fs::read_to_string(config.file_path)?;
println!("Content:\n {}", content);
Ok(())
}

struct Config {
Expand Down

0 comments on commit cfc15b0

Please sign in to comment.