fs-tracing

Crates.iofs-tracing
lib.rsfs-tracing
version0.1.0
sourcesrc
created_at2021-02-25 13:05:17.575512
updated_at2021-02-25 13:05:17.575512
descriptionA drop-in replacement for std::fs which provides useful information on error
homepage
repositoryhttps://github.com/pandaman64/fs-tracing
max_upload_size
id360416
size53,694
pandaman (pandaman64)

documentation

README

fs-tracing

fs-tracing is a drop-in replacement for std::fs that provides an auxiliary information (such as paths) on error via tracing.

Usage

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.

Errors

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

License

Licensed under either of

at your option.

Contribution

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.

Commit count: 7

cargo fmt