MCPcopy Index your code
hub / github.com/andrewhickman/fs-err

github.com/andrewhickman/fs-err @3.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 3.3.0 ↗ · + Follow
202 symbols 288 edges 15 files 107 documented · 53% updated 4d ago★ 17610 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

fs-err

Crates.io GitHub Actions

fs-err is a drop-in replacement for 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, 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`: 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);

Feature flags

  • expose_original_error: when enabled, the Error::source() method of errors returned by this crate return the original io::Error. To avoid duplication in error messages, this also suppresses printing its message in their Display implementation, so make sure that you are printing the full error chain.
  • debug: Debug filesystem errors faster by exposing more information. When a filesystem command fails, the error message might say "file does not exist." But it won't say why it doesn't exist. Perhaps the programmer misspelled the filename, perhaps that directory doesn't exist, or if it does, but the current user doesn't have permissions to see the contents. This feature analyzes the filesystem to output various "facts" that will help a developer debug the root of the current error.
  • Warning: Exposes filesystem metadata. This feature exposes additional metadata about your filesystem such as directory contents and permissions, which may be sensitive. Only enable debug when error messages won't be displayed to the end user, or they have access to filesystem metadata some other way.
  • Warning: This may slow down your program. This feature will trigger additional filesystem calls when errors occur, which may cause performance issues. Do not use if filesystem errors are common on a performance-sensitive "hotpath." Use in scenarios where developer hours are more expensive than compute time.
  • To mitigate performance and security concerns, consider only enabling this feature in dev-dependencies:
  • Requires Rust 1.79 or later
[dev-dependencies]
fs-err = { features = ["debug"] }

To use with the tokio feature, use debug_tokio:

[dependencies]
fs-err = { features = ["debug_tokio", "tokio"] }

Minimum Supported Rust Version

The oldest rust version this crate is tested on is 1.40.

This crate will generally be conservative with rust version updates. It uses the autocfg crate to allow wrapping new APIs without incrementing the MSRV.

If the tokio feature is enabled, this crate will inherit the MSRV of the selected tokio version.

License

Licensed under either of

  • Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)

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.

Extension points exported contracts — how you extend this code

FileExt (Interface)
Wrapper for [`std::os::unix::fs::FileExt`]. The std traits might be extended in the future (See issue [#49961](https:// [2 …
src/os/unix.rs
Sealed (Interface)
(no doc) [3 implementers]
src/lib.rs
PathExt (Interface)
Defines aliases on [`std::path::Path`] for fs-err functions. This trait is sealed and can not be implemented by other c [1 …
src/path.rs
OpenOptionsExt (Interface)
Wrapper for [`std::os::unix::fs::OpenOptionsExt`]. The std traits might be extended in the future (See issue [#49961](h [2 …
src/os/unix.rs
FileExt (Interface)
Wrapper for [`std::os::windows::fs::FileExt`]. The std traits might be extended in the future (See issue [#49961](https
src/os/windows.rs
OpenOptionsExt (Interface)
Wrapper for [`std::os::windows::fs::OpenOptionsExt`]. The std traits might be extended in the future (See issue [#49961
src/os/windows.rs

Core symbols most depended-on inside this repo

error
called by 29
src/file.rs
error
called by 13
src/tokio/file.rs
file
called by 10
src/file.rs
options_mut
called by 7
src/open_options.rs
open
called by 4
src/file.rs
create
called by 3
src/file.rs
into_parts
called by 3
src/tokio/file.rs
source
called by 2
src/errors.rs

Shape

Method 129
Function 54
Class 11
Interface 6
Enum 2

Languages

Rust100%

Modules by API surface

src/file.rs47 symbols
src/tokio/file.rs31 symbols
src/tokio/mod.rs20 symbols
src/lib.rs20 symbols
src/open_options.rs18 symbols
src/tokio/open_options.rs12 symbols
src/errors.rs12 symbols
src/tokio/read_dir.rs10 symbols
src/dir.rs9 symbols
src/path.rs7 symbols
src/os/unix.rs6 symbols
src/tokio/dir_builder.rs5 symbols

For agents

$ claude mcp add fs-err \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact