Crate fs_tracing

Source
Expand description

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

Structs§

DirBuilder
Wrapper for fs::DirBuilder.
DirEntry
Wrapper for fs::DirEntry.
File
Wrapper for fs::File.
FileType
Wrapper for fs::FileType.
Metadata
Wrapper for fs::Metadata.
OpenOptions
Wrapper for fs::OpenOptions.
Permissions
Wrapper for fs::Permissions.
ReadDir
Wrapper for fs::ReadDir.

Functions§

canonicalize
Wrapper for fs::canonicalize.
copy
Wrapper for fs::copy.
create_dir
Wrapper for fs::create_dir.
create_dir_all
Wrapper for fs::create_dir_all.
hard_link
Wrapper for fs::hard_link.
metadata
Wrapper for fs::metadata.
read
Wrapper for fs::read.
read_dir
Wrapper for fs::read_dir.
read_link
Wrapper for fs::read_link.
read_to_string
Wrapper for fs::read_to_string.
remove_dir
Wrapper for fs::remove_dir.
remove_dir_all
Wrapper for fs::remove_dir_all.
remove_file
Wrapper for fs::remove_file.
rename
Wrapper for fs::rename.
set_permissions
Wrapper for fs::set_permissions.
symlink_metadata
Wrapper for fs::symlink_metadata.
write
Wrapper for fs::write.