Normalize error handling to into_diagnostic().context()
Replaces map_err(|e| miette!("...: {e}")) with into_diagnostic()
followed by context("..."). This preserves the full error chain in
miette output instead of flattening it into a string.

The only wrinkle: StripPrefixError doesn't implement miette's Diag
trait, so strip_prefix() needs .into_diagnostic() before .context().

Assisted-by: GLM-5.1 via pi
change lpvrsnmmwzpluzrrtmpwvlvnxqpplqlq
commit 21e45f87e1f4ddcf4cca3e5549b287638104ce74
author Alpha Chen <alpha@kejadlen.dev>
date
parent xzvrlumk
diff --git a/src/bin/quire/commands/hook.rs b/src/bin/quire/commands/hook.rs
index 08cc6da..b20a417 100644
--- a/src/bin/quire/commands/hook.rs
+++ b/src/bin/quire/commands/hook.rs
@@ -1,6 +1,6 @@
 use std::io::{self, IsTerminal};
 
-use miette::{Context, IntoDiagnostic, Result, bail, ensure, miette};
+use miette::{Context, IntoDiagnostic, Result, bail, ensure};
 use quire::Quire;
 
 const ZERO_SHA: &str = "0000000000000000000000000000000000000000";
@@ -37,13 +37,14 @@ fn post_receive(quire: &Quire) -> Result<()> {
     // are invoked via hook.<name>.command, GIT_DIR may be relative (e.g.
     // "."), so canonicalize before resolving.
     let git_dir = std::env::var("GIT_DIR")
-        .map_err(|e| miette!("GIT_DIR not set — hook must run inside a bare repo: {e}"))
+        .into_diagnostic()
+        .context("GIT_DIR not set — hook must run inside a bare repo")
         .and_then(|git_dir| {
             std::path::Path::new(&git_dir)
                 .canonicalize()
                 .into_diagnostic()
-        })
-        .map_err(|e| miette!("failed to resolve GIT_DIR: {e}"))?;
+                .context("failed to resolve GIT_DIR")
+        })?;
 
     let repo = quire
         .repo_from_path(&git_dir)
@@ -59,7 +60,9 @@ fn post_receive(quire: &Quire) -> Result<()> {
     let stdin = io::stdin();
     let mut refs: Vec<quire::event::PushRef> = Vec::new();
     for line in stdin.lines() {
-        let line = line.map_err(|e| miette!("failed to read hook stdin: {e}"))?;
+        let line = line
+            .into_diagnostic()
+            .context("failed to read hook stdin")?;
         let parts: Vec<&str> = line.split_whitespace().collect();
         if parts.len() != 3 {
             continue;
@@ -83,7 +86,8 @@ fn post_receive(quire: &Quire) -> Result<()> {
     let repo_name = repo
         .path()
         .strip_prefix(quire.repos_dir())
-        .map_err(|_| miette!("repo path not under repos dir"))?
+        .into_diagnostic()
+        .context("repo path not under repos dir")?
         .to_string_lossy()
         .to_string();
 
diff --git a/src/quire.rs b/src/quire.rs
index d12c304..86e9438 100644
--- a/src/quire.rs
+++ b/src/quire.rs
@@ -1,6 +1,6 @@
 use std::path::{Path, PathBuf};
 
-use miette::{IntoDiagnostic, Result, ensure, miette};
+use miette::{Context, IntoDiagnostic, Result, ensure};
 
 use crate::fennel::Fennel;
 use crate::secret::SecretString;
@@ -84,9 +84,10 @@ impl Repo {
     /// Verifies the path falls under `base` and passes name validation.
     /// Used by hooks that receive `GIT_DIR` from git.
     pub fn from_path(base: &Path, path: &Path) -> Result<Self> {
-        let relative = path
-            .strip_prefix(base)
-            .map_err(|_| miette!("path is not under repos directory: {}", path.display()))?;
+        let relative = path.strip_prefix(base).into_diagnostic().context(format!(
+            "path is not under repos directory: {}",
+            path.display()
+        ))?;
         let name = relative.to_string_lossy();
         Self::validate_name(&name)?;
         Ok(Self {