Use fs_err instead of std::fs
Includes path context in error messages automatically.
clippy.toml disallows std::fs methods to enforce this.
Assisted-by: Claude Opus 4.6 via pi
diff --git a/Cargo.lock b/Cargo.lock
index 471725d..47618f2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -76,6 +76,12 @@ dependencies = [
"windows-sys",
]
+[[package]]
+name = "autocfg"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
+
[[package]]
name = "backtrace"
version = "0.3.76"
@@ -180,6 +186,15 @@ dependencies = [
"once_cell",
]
+[[package]]
+name = "fs-err"
+version = "3.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73fde052dbfc920003cfd2c8e2c6e6d4cc7c1091538c3a24226cec0665ab08c0"
+dependencies = [
+ "autocfg",
+]
+
[[package]]
name = "gimli"
version = "0.32.3"
@@ -312,6 +327,7 @@ version = "0.1.0"
dependencies = [
"clap",
"color-eyre",
+ "fs-err",
"tracing",
"tracing-subscriber",
"xdg",
diff --git a/Cargo.toml b/Cargo.toml
index 2180b73..f3164b7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,6 +8,7 @@ edition = "2024"
[dependencies]
clap = { version = "*", features = ["derive"] }
color-eyre = "*"
+fs-err = "*"
tracing = "*"
tracing-subscriber = { version = "*", features = ["env-filter"] }
-xdg = "3.0.0"
+xdg = "*"
diff --git a/clippy.toml b/clippy.toml
new file mode 100644
index 0000000..e8f917e
--- /dev/null
+++ b/clippy.toml
@@ -0,0 +1,10 @@
+disallowed-methods = [
+ { path = "std::fs::read_to_string", reason = "use fs_err::read_to_string" },
+ { path = "std::fs::write", reason = "use fs_err::write" },
+ { path = "std::fs::read_dir", reason = "use fs_err::read_dir" },
+ { path = "std::fs::remove_file", reason = "use fs_err::remove_file" },
+ { path = "std::fs::remove_dir_all", reason = "use fs_err::remove_dir_all" },
+ { path = "std::fs::create_dir_all", reason = "use fs_err::create_dir_all" },
+ { path = "std::fs::read_link", reason = "use fs_err::read_link" },
+ { path = "std::fs::symlink_metadata", reason = "use fs_err::symlink_metadata" },
+]
diff --git a/src/main.rs b/src/main.rs
index 3d5be6a..db45279 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,3 @@
-use std::fs;
use std::path::PathBuf;
use std::process::{Command, ExitCode, Stdio};
@@ -53,10 +52,8 @@ fn run() -> Result<()> {
let cache_dir = xdg
.create_cache_directory("")
.wrap_err("failed to create cache directory")?;
- fs::write(cache_dir.join("compose.yml"), COMPOSE_YML)
- .wrap_err("failed to write compose.yml")?;
- fs::write(cache_dir.join("Dockerfile"), DOCKERFILE)
- .wrap_err("failed to write Dockerfile")?;
+ fs_err::write(cache_dir.join("compose.yml"), COMPOSE_YML)?;
+ fs_err::write(cache_dir.join("Dockerfile"), DOCKERFILE)?;
let compose_file = cache_dir.join("compose.yml");