Crates.io | fs-tracing |
lib.rs | fs-tracing |
version | 0.1.0 |
source | src |
created_at | 2021-02-25 13:05:17.575512 |
updated_at | 2021-02-25 13:05:17.575512 |
description | A drop-in replacement for std::fs which provides useful information on error |
homepage | |
repository | https://github.com/pandaman64/fs-tracing |
max_upload_size | |
id | 360416 |
size | 53,694 |
fs-tracing is a drop-in replacement for std::fs
that provides an auxiliary
information (such as paths) on error via tracing
.
You need to install tracing_error::ErrorLayer
for capturing the error context. For example, the following function installs ErrorLayer
.
// https://docs.rs/tracing-error/0.1.2/tracing_error/index.html
pub fn install() {
use tracing_error::ErrorLayer;
use tracing_subscriber::prelude::*;
let subscriber = tracing_subscriber::Registry::default().with(ErrorLayer::default());
tracing::subscriber::set_global_default(subscriber).unwrap();
}
For more information, please visit https://docs.rs/tracing-subscriber/0.2.16/tracing_subscriber/registry/index.html.
Then, you can replace std::fs
with fs_tracing
in your code and you get nice error messages.
fs-tracing returns std::io::Error
on errors for compatibility, although
the returned error contains the context information such as the kind of the operation and the
values passed as arguments.
For example, when you open a file which does not exist, the error message returned by fs-tracing
prints the operation name (fs_tracing::read
) and the offending path (/not_exist
):
No such file or directory (os error 2)
Trace:
0: fs_tracing::read
with path="/not_exist"
at src/lib.rs:652
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.