Feat: Add custom error message.

This commit is contained in:
Ian Rettig
2025-06-06 17:50:44 -04:00
parent d7d2c74b23
commit f9418783d4
+6 -2
View File
@@ -7,12 +7,16 @@ struct Cli {
path: std::path::PathBuf,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
#[derive(Debug)]
struct CustomError(String);
fn main() -> Result<(), CustomError> {
let args = Cli::parse();
// let content = std::fs::read_to_string(&args.path).expect("Could not read file.");
let content = std::fs::read_to_string(&args.path)?;
let content = std::fs::read_to_string(&args.path)
.map_err(|err| CustomError(format!("Error reading `{}`: {}", args.path.display(), err)))?;
for line in content.lines() {
if line.contains(&args.pattern) {