[][src]Crate fs_err

fs-err is a drop-in replacement for std::fs that provides more helpful messages on errors. Extra information includes which operations was attmpted and any involved paths.

Error Messages

Using std::fs, if this code fails:

let file = File::open("does not exist.txt")?;

The error message that Rust gives you isn't very useful:

The system cannot find the file specified. (os error 2)

...but if we use fs-err instead, our error contains more actionable information:

failed to open file `does not exist.txt`
    caused by: The system cannot find the file specified. (os error 2)

Usage

fs-err's API is the same as std::fs, so migrating code to use it is easy.

// use std::fs;
use fs_err as fs;

let contents = fs::read_to_string("foo.txt")?;

println!("Read foo.txt: {}", contents);

fs-err uses std::io::Error for all errors. This helps fs-err compose well with traits from the standard library like std::io::Read and crates that use them like serde_json:

use fs_err::File;

let file = File::open("my-config.json")?;

// If an I/O error occurs inside serde_json, the error will include a file path
// as well as what operation was being performed.
let decoded: Vec<String> = serde_json::from_reader(file)?;

println!("Program config: {:?}", decoded);

Modules

os

OS-specific functionality.

Structs

DirEntry

Wrapper around std::fs::DirEntry which adds more helpful information to all errors.

File

Wrapper around std::fs::File which adds more helpful information to all errors.

OpenOptions

Wrapper around std::fs::OptionOptions

ReadDir

Wrapper around std::fs::ReadDir which adds more helpful information to all errors.

Traits

PathExt

Defines aliases on Path for fs_err functions.

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.

soft_linkDeprecated

Wrapper for fs::soft_link.

symlink_metadata

Wrapper for fs::symlink_metadata.

write

Wrapper for fs::write.