Add Diagnostic to MigrationError and ApiError, remove redundant into_diagnostic calls
MigrationError (db.rs) and ApiError (web/api.rs) now derive miette::Diagnostic,
which means ? auto-converts them to miette::Report at miette boundaries.
Five .into_diagnostic() calls on already-Diagnostic error types (quire::Error,
ci::Error, MigrationError via db::migrate) were replaced with plain ?.
change otoqsnulkssmmwzkqxzzlmkuzzqwsmro
commit c6eb158e1f457e1c92d1f40af81cdbd31a9086e8
author Alpha Chen <alpha@kejadlen.dev>
date
parent fd369df4
diff --git a/quire-server/src/bin/quire/commands/ci.rs b/quire-server/src/bin/quire/commands/ci.rs
index 4455273..c390603 100644
--- a/quire-server/src/bin/quire/commands/ci.rs
+++ b/quire-server/src/bin/quire/commands/ci.rs
@@ -49,7 +49,7 @@ pub async fn run(quire: &Quire, maybe_sha: Option<&str>) -> Result<()> {
     match quire.global_config() {
         Ok(_) => {}
         Err(quire::Error::ConfigNotFound(_)) => {}
-        Err(e) => return Err(e).into_diagnostic(),
+        Err(e) => return Err(e)?,
     };
 
     let Some(_pipeline) = ci.pipeline(&commit)? else {
@@ -63,7 +63,7 @@ pub async fn run(quire: &Quire, maybe_sha: Option<&str>) -> Result<()> {
     let tmp = tempfile::tempdir().into_diagnostic()?;
     let db_path = tmp.path().join("quire.db");
     let mut db = quire::db::open(&db_path).into_diagnostic()?;
-    quire::db::migrate(&mut db).into_diagnostic()?;
+    quire::db::migrate(&mut db)?;
     drop(db);
     let runs = Runs::new(db_path, "local".to_string(), tmp.path().to_path_buf());
 
@@ -83,8 +83,7 @@ pub async fn run(quire: &Quire, maybe_sha: Option<&str>) -> Result<()> {
     );
 
     let workspace = tmp.path().join("workspace");
-    quire::ci::materialize_workspace(&repo_path.join(".git"), &commit.sha, &workspace)
-        .into_diagnostic()?;
+    quire::ci::materialize_workspace(&repo_path.join(".git"), &commit.sha, &workspace)?;
     let exec_result = run.execute(&repo_path.join(".git"), &workspace, None, None, None);
 
     // Print the combined quire-ci log regardless of outcome.
@@ -105,7 +104,7 @@ pub async fn run(quire: &Quire, maybe_sha: Option<&str>) -> Result<()> {
         }
         Err(e) => {
             println!("\nRun failed.");
-            Err(e).into_diagnostic()
+            Err(e)?
         }
     }
 }
diff --git a/quire-server/src/bin/quire/commands/dev.rs b/quire-server/src/bin/quire/commands/dev.rs
index 527b864..16159aa 100644
--- a/quire-server/src/bin/quire/commands/dev.rs
+++ b/quire-server/src/bin/quire/commands/dev.rs
@@ -78,9 +78,7 @@ impl Seeder {
         let mut db = quire::db::open(&quire.db_path())
             .into_diagnostic()
             .context("failed to open database")?;
-        quire::db::migrate(&mut db)
-            .into_diagnostic()
-            .context("failed to run migrations")?;
+        quire::db::migrate(&mut db).context("failed to run migrations")?;
 
         Ok(Self {
             quire,
diff --git a/quire-server/src/bin/quire/commands/hook.rs b/quire-server/src/bin/quire/commands/hook.rs
index 000d1b6..d01a55d 100644
--- a/quire-server/src/bin/quire/commands/hook.rs
+++ b/quire-server/src/bin/quire/commands/hook.rs
@@ -51,8 +51,8 @@ fn post_receive(quire: &Quire) -> Result<()> {
         .context("hook running in unrecognized repo")?;
     ensure!(
         repo.exists(),
-        "GIT_DIR points to a non-existent repo: {}",
-        git_dir.display()
+        "GIT_DIR points to a non-existent repo: {:?}",
+        git_dir
     );
 
     // Parse pushed refs from stdin. Each line is:
diff --git a/quire-server/src/bin/quire/server.rs b/quire-server/src/bin/quire/server.rs
index b39b434..d803f1b 100644
--- a/quire-server/src/bin/quire/server.rs
+++ b/quire-server/src/bin/quire/server.rs
@@ -54,7 +54,7 @@ pub async fn run(quire: &Quire, web_routes: axum::Router, api_routes: axum::Rout
     let db_path = quire.db_path();
     tracing::info!(path = %db_path.display(), "opening database");
     let mut db = quire::db::open(&db_path).into_diagnostic()?;
-    quire::db::migrate(&mut db).into_diagnostic()?;
+    quire::db::migrate(&mut db)?;
     drop(db);
 
     // Reconcile any orphaned runs from a previous server instance.
diff --git a/quire-server/src/db.rs b/quire-server/src/db.rs
index 45d23ca..5d0fb0e 100644
--- a/quire-server/src/db.rs
+++ b/quire-server/src/db.rs
@@ -26,7 +26,7 @@ static MIGRATIONS: std::sync::LazyLock<Migrations<'static>> = std::sync::LazyLoc
 });
 
 /// Error from running migrations.
-#[derive(Debug, thiserror::Error)]
+#[derive(Debug, thiserror::Error, miette::Diagnostic)]
 pub enum MigrationError {
     #[error(transparent)]
     Sqlite(#[from] rusqlite::Error),
diff --git a/quire-server/src/mirror.rs b/quire-server/src/mirror.rs
index 863292b..32bec81 100644
--- a/quire-server/src/mirror.rs
+++ b/quire-server/src/mirror.rs
@@ -2,7 +2,7 @@
 //!
 //! Triggered from the push event handler, independent of CI.
 
-use miette::{Diagnostic, IntoDiagnostic as _};
+use miette::Diagnostic;
 use quire_core::event::{PushEvent, PushRef};
 use thiserror::Error;
 
@@ -42,13 +42,12 @@ pub fn trigger(quire: &Quire, event: &PushEvent) -> miette::Result<()> {
         return Err(MirrorError::RepoNotFound(event.repo.clone()).into());
     }
 
-    let config = quire.global_config().into_diagnostic()?;
+    let config = quire.global_config()?;
     let Some(mirror_token) = config
         .github
         .mirror_token
         .map(|s| s.reveal().map(str::to_owned))
-        .transpose()
-        .into_diagnostic()?
+        .transpose()?
     else {
         return Ok(());
     };
diff --git a/quire-server/src/quire/web/api.rs b/quire-server/src/quire/web/api.rs
index 533d9b0..1e4db80 100644
--- a/quire-server/src/quire/web/api.rs
+++ b/quire-server/src/quire/web/api.rs
@@ -39,7 +39,7 @@ pub fn router(quire: Quire) -> axum::Router {
         .with_state(quire)
 }
 
-#[derive(Debug, thiserror::Error)]
+#[derive(Debug, thiserror::Error, miette::Diagnostic)]
 enum ApiError {
     #[error("not found")]
     NotFound,