Find
C
ase-sensitive
R
egexp search
Path
comm-central
/
third_party
/
rust
/
fs-err
/
src
Navigation
Enable keyboard shortcuts
Name
Description
Size
dir.rs
2804
errors.rs
6086
file.rs
12213
lib.rs
! fs-err is a drop-in replacement for [`std::fs`][std::fs] that provides more helpful messages on errors. Extra information includes which operations was attempted and any involved paths. # Error Messages Using [`std::fs`][std::fs], if this code fails: ```no_run # use std::fs::File; let file = File::open("does not exist.txt")?; # Ok::<(), std::io::Error>(()) ``` The error message that Rust gives you isn't very useful: ```txt The system cannot find the file specified. (os error 2) ``` ...but if we use fs-err instead, our error contains more actionable information: ```txt 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`][std::fs], so migrating code to use it is easy. ```no_run // use std::fs; use fs_err as fs; let contents = fs::read_to_string("foo.txt")?; println!("Read foo.txt: {}", contents); # Ok::<(), std::io::Error>(()) ``` fs-err uses [`std::io::Error`][std::io::Error] for all errors. This helps fs-err compose well with traits from the standard library like [`std::io::Read`][std::io::Read] and crates that use them like [`serde_json`][serde_json]: ```no_run 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); # Ok::<(), Box<dyn std::error::Error>>(()) ``` [std::fs]: https://doc.rust-lang.org/stable/std/fs/ [std::io::Error]: https://doc.rust-lang.org/stable/std/io/struct.Error.html [std::io::Read]: https://doc.rust-lang.org/stable/std/io/trait.Read.html [serde_json]: https://crates.io/crates/serde_json
8898
open_options.rs
5109
os
os.rs
OS-specific functionality.
366
path.rs
1453
tokio