Feat: Add custom error message.
This commit is contained in:
+6
-2
@@ -7,12 +7,16 @@ struct Cli {
|
|||||||
path: std::path::PathBuf,
|
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 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).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() {
|
for line in content.lines() {
|
||||||
if line.contains(&args.pattern) {
|
if line.contains(&args.pattern) {
|
||||||
|
|||||||
Reference in New Issue
Block a user