refactor: Replace Context trait with WrapErr
Assisted-by: Claude Opus 4.6 via pi
change xnrolxsrovyuxvtrtvnltwrvwlpxzswv
commit 2b6189e0a879f7a8f385f2ca68015a75bc051ede
author Alpha Chen <alpha@kejadlen.dev>
date
parent yvslwqoq
diff --git a/src/config.rs b/src/config.rs
index 6bb9dbb..fbe009b 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,8 +1,7 @@
 use std::collections::BTreeMap;
 use std::collections::HashSet;
 
-use color_eyre::eyre::eyre;
-use color_eyre::eyre::{Context, Result, bail};
+use color_eyre::eyre::{Result, WrapErr, bail, eyre};
 use serde::Deserialize;
 
 #[derive(Debug, Clone)]
@@ -43,7 +42,7 @@ pub fn load() -> Result<Vec<Plugin>> {
         let path = entry.path();
         let contents = fs_err::read_to_string(&path)?;
         let file: ConfigFile = serde_yml::from_str(&contents)
-            .with_context(|| format!("failed to parse {}", path.display()))?;
+            .wrap_err_with(|| format!("failed to parse {}", path.display()))?;
 
         let marketplaces = &file.marketplaces;
 
diff --git a/src/git.rs b/src/git.rs
index fc05c93..910e624 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -1,7 +1,7 @@
 use std::path::{Path, PathBuf};
 use std::process::Command;
 
-use color_eyre::eyre::{Context, Result, bail};
+use color_eyre::eyre::{Result, WrapErr, bail};
 use tracing::info;
 
 /// Derive a bare repo path from a remote URL.
@@ -27,7 +27,7 @@ pub fn clone_or_fetch(repo_path: &Path, src: &str) -> Result<()> {
             .args(["fetch", "--quiet", "origin"])
             .current_dir(repo_path)
             .status()
-            .context("failed to run git fetch")?;
+            .wrap_err("failed to run git fetch")?;
         if !status.success() {
             bail!("git fetch failed for {}", src);
         }
@@ -37,7 +37,7 @@ pub fn clone_or_fetch(repo_path: &Path, src: &str) -> Result<()> {
             .args(["clone", "--quiet", "--bare", src, "."])
             .current_dir(repo_path)
             .status()
-            .context("failed to run git clone")?;
+            .wrap_err("failed to run git clone")?;
         if !status.success() {
             bail!("git clone failed for {}", src);
         }
@@ -51,7 +51,7 @@ pub fn resolve_ref(repo_path: &Path, git_ref: &str) -> Result<String> {
         .args(["rev-parse", &format!("origin/{git_ref}")])
         .current_dir(repo_path)
         .output()
-        .context("failed to run git rev-parse")?;
+        .wrap_err("failed to run git rev-parse")?;
 
     if output.status.success() {
         return Ok(String::from_utf8_lossy(&output.stdout).trim().to_string());
@@ -62,7 +62,7 @@ pub fn resolve_ref(repo_path: &Path, git_ref: &str) -> Result<String> {
         .args(["rev-parse", git_ref])
         .current_dir(repo_path)
         .output()
-        .context("failed to run git rev-parse")?;
+        .wrap_err("failed to run git rev-parse")?;
 
     if !output.status.success() {
         bail!(
@@ -85,7 +85,7 @@ pub fn ensure_worktree(repo_path: &Path, rev: &str) -> Result<PathBuf> {
             .args(["checkout", "--quiet", "--detach", rev])
             .current_dir(&wt_path)
             .status()
-            .context("failed to run git checkout in worktree")?;
+            .wrap_err("failed to run git checkout in worktree")?;
         if !status.success() {
             bail!("git checkout failed for {} in {}", rev, wt_path.display());
         }
@@ -102,7 +102,7 @@ pub fn ensure_worktree(repo_path: &Path, rev: &str) -> Result<PathBuf> {
             ])
             .current_dir(repo_path)
             .status()
-            .context("failed to run git worktree add")?;
+            .wrap_err("failed to run git worktree add")?;
         if !status.success() {
             bail!(
                 "git worktree add failed for {} in {}",
diff --git a/src/lockfile.rs b/src/lockfile.rs
index dd47291..83ee61c 100644
--- a/src/lockfile.rs
+++ b/src/lockfile.rs
@@ -1,6 +1,6 @@
 use std::collections::BTreeMap;
 
-use color_eyre::eyre::{Context, Result};
+use color_eyre::eyre::{Result, WrapErr};
 use serde::{Deserialize, Serialize};
 
 #[derive(Debug, Clone, Serialize, Deserialize)]
@@ -20,13 +20,13 @@ pub fn load() -> Result<Lockfile> {
     let path = crate::paths::lockfile_path()?;
     let contents = fs_err::read_to_string(&path)?;
     let lockfile: Lockfile = serde_yml::from_str(&contents)
-        .with_context(|| format!("failed to parse lockfile: {}", path.display()))?;
+        .wrap_err_with(|| format!("failed to parse lockfile: {}", path.display()))?;
     Ok(lockfile)
 }
 
 pub fn save(lockfile: &Lockfile) -> Result<()> {
     let path = crate::paths::lockfile_path()?;
-    let contents = serde_yml::to_string(lockfile).context("failed to serialize lockfile")?;
+    let contents = serde_yml::to_string(lockfile).wrap_err("failed to serialize lockfile")?;
     fs_err::write(&path, contents)?;
     Ok(())
 }
diff --git a/src/main.rs b/src/main.rs
index c84be52..5bb135c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,7 +7,7 @@ mod marketplace;
 mod paths;
 
 use clap::{Parser, Subcommand};
-use color_eyre::eyre::{Context, Result, bail};
+use color_eyre::eyre::{Result, WrapErr, bail};
 use tracing::info;
 
 #[derive(Parser)]
@@ -79,7 +79,7 @@ fn main() -> Result<()> {
 }
 
 fn do_update(names: &[String]) -> Result<()> {
-    let all_plugins = config::load().context("failed to load config")?;
+    let all_plugins = config::load().wrap_err("failed to load config")?;
 
     let (plugins, mut lockfile) = if names.is_empty() {
         (
@@ -142,13 +142,13 @@ fn do_update(names: &[String]) -> Result<()> {
         );
     }
 
-    lockfile::save(&lockfile).context("failed to save lockfile")?;
+    lockfile::save(&lockfile).wrap_err("failed to save lockfile")?;
     info!("lockfile updated");
     Ok(())
 }
 
 fn do_install() -> Result<()> {
-    let lockfile = lockfile::load().context("no lockfile found — run `pinch update` first")?;
+    let lockfile = lockfile::load().wrap_err("no lockfile found — run `pinch update` first")?;
 
     let repos_dir = paths::repos_dir()?;
     let skills_dir = paths::skills_dir()?;
@@ -257,7 +257,7 @@ fn symlink_entries(
             fs_err::remove_file(&symlink_path)?;
         }
 
-        std::os::unix::fs::symlink(entry.path(), &symlink_path).with_context(|| {
+        std::os::unix::fs::symlink(entry.path(), &symlink_path).wrap_err_with(|| {
             format!(
                 "failed to create symlink: {} -> {}",
                 symlink_path.display(),
diff --git a/src/marketplace.rs b/src/marketplace.rs
index c6f0c1e..4e3a569 100644
--- a/src/marketplace.rs
+++ b/src/marketplace.rs
@@ -1,6 +1,6 @@
 use std::path::Path;
 
-use color_eyre::eyre::{Context, Result, bail, eyre};
+use color_eyre::eyre::{Result, WrapErr, bail, eyre};
 use serde::Deserialize;
 
 const DEFAULT_PATH: &str = ".claude-plugin/marketplace.json";
@@ -41,7 +41,7 @@ pub fn find_plugin_source(
     let contents = fs_err::read_to_string(&manifest_path)?;
 
     let marketplace: Marketplace = serde_json::from_str(&contents)
-        .with_context(|| format!("failed to parse {}", manifest_path.display()))?;
+        .wrap_err_with(|| format!("failed to parse {}", manifest_path.display()))?;
 
     let plugin = marketplace
         .plugins
diff --git a/src/paths.rs b/src/paths.rs
index bcf38ca..14adffd 100644
--- a/src/paths.rs
+++ b/src/paths.rs
@@ -1,6 +1,6 @@
 use std::path::PathBuf;
 
-use color_eyre::eyre::{Context, Result};
+use color_eyre::eyre::{Result, WrapErr};
 use xdg::BaseDirectories;
 
 fn base_dirs() -> BaseDirectories {
@@ -17,13 +17,13 @@ pub fn config_dir() -> PathBuf {
 pub fn repos_dir() -> Result<PathBuf> {
     base_dirs()
         .create_cache_directory("repos")
-        .context("failed to create repos dir")
+        .wrap_err("failed to create repos dir")
 }
 
 pub fn lockfile_path() -> Result<PathBuf> {
     base_dirs()
         .place_data_file("pinch-lock.yml")
-        .context("failed to create data dir")
+        .wrap_err("failed to create data dir")
 }
 
 pub fn skills_dir() -> Result<PathBuf> {