forked from mirror/async-std
8ce3e78952
This adds a new "verbose-errors" feature flag to async-std that enables wrapping certain errors in structures with more context. As an example, we use it in `fs::File::{open,create}` to add the given path to the error message (something that is lacking in std to annoyance of many).
20 lines
676 B
Rust
20 lines
676 B
Rust
#[cfg(feature = "verbose-errors")]
|
|
mod verbose_tests {
|
|
use async_std::{fs, task};
|
|
|
|
#[test]
|
|
fn open_file() {
|
|
task::block_on(async {
|
|
let non_existing_file =
|
|
"/ashjudlkahasdasdsikdhajik/asdasdasdasdasdasd/fjuiklashdbflasas";
|
|
let res = fs::File::open(non_existing_file).await;
|
|
match res {
|
|
Ok(_) => panic!("Found file with random name: We live in a simulation"),
|
|
Err(e) => assert_eq!(
|
|
"Could not open /ashjudlkahasdasdsikdhajik/asdasdasdasdasdasd/fjuiklashdbflasas",
|
|
&format!("{}", e)
|
|
),
|
|
}
|
|
})
|
|
}
|
|
}
|