adding error context
This commit is contained in:
parent
2d5ac33cf9
commit
baf6df0fe7
1 changed files with 7 additions and 2 deletions
|
@ -6,8 +6,13 @@ struct Cli {
|
|||
path: std::path::PathBuf,
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let content = std::fs::read_to_string("test.txt")?;
|
||||
#[derive(Debug)]
|
||||
struct CustomError(String);
|
||||
|
||||
fn main() -> Result<(), CustomError> {
|
||||
let path = "test.txt";
|
||||
let content = std::fs::read_to_string(path)
|
||||
.map_err(|err| CustomError(format!("Error reading `{}`: {}", path, err)))?;
|
||||
println!("file content: {}", content);
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue