From b965c5a2e607255bbc5efd84174e8a3e5a215551 Mon Sep 17 00:00:00 2001 From: Per Stark Date: Mon, 25 May 2026 13:48:31 +0200 Subject: [PATCH] refactor: replace Box with anyhow::Result - ingestion_pipeline::run_worker_loop returns anyhow::Result<()> - api_router::ApiState::new returns anyhow::Result - html_router::HtmlState::new_with_resources is infallible, returns Self - main/server/worker binary entry points return anyhow::Result<()> --- api-router/src/api_state.rs | 2 +- html-router/src/html_state.rs | 6 +++--- ingestion-pipeline/src/lib.rs | 2 +- main/src/main.rs | 7 +++---- main/src/server.rs | 4 ++-- main/src/worker.rs | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/api-router/src/api_state.rs b/api-router/src/api_state.rs index 5c1735d..c9ba09b 100644 --- a/api-router/src/api_state.rs +++ b/api-router/src/api_state.rs @@ -16,7 +16,7 @@ impl ApiState { pub async fn new( config: &AppConfig, storage: StorageManager, - ) -> Result> { + ) -> anyhow::Result { let surreal_db_client = Arc::new( SurrealDbClient::new( &config.surrealdb_address, diff --git a/html-router/src/html_state.rs b/html-router/src/html_state.rs index 96279fc..084f9f2 100644 --- a/html-router/src/html_state.rs +++ b/html-router/src/html_state.rs @@ -49,12 +49,12 @@ impl HtmlState { reranker_pool: Option>, embedding_provider: Arc, template_engine: Option>, - ) -> Result> { + ) -> Self { let templates = template_engine.unwrap_or_else(|| Arc::new(create_template_engine!("templates"))); debug!("Template engine configured for html_router."); - Ok(Self { + Self { db, openai_client, session_store, @@ -65,7 +65,7 @@ impl HtmlState { embedding_provider, conversation_archive_cache: Arc::new(RwLock::new(HashMap::new())), conversation_archive_cache_writes: Arc::new(AtomicUsize::new(0)), - }) + } } pub fn retrieval_strategy(&self) -> RetrievalStrategy { diff --git a/ingestion-pipeline/src/lib.rs b/ingestion-pipeline/src/lib.rs index 6ae0b4f..b944808 100644 --- a/ingestion-pipeline/src/lib.rs +++ b/ingestion-pipeline/src/lib.rs @@ -17,7 +17,7 @@ use uuid::Uuid; pub async fn run_worker_loop( db: Arc, ingestion_pipeline: Arc, -) -> Result<(), Box> { +) -> anyhow::Result<()> { let worker_id = format!("ingestion-worker-{}", Uuid::new_v4()); let lease_duration = Duration::from_secs(DEFAULT_LEASE_SECS as u64); let idle_backoff = Duration::from_millis(500); diff --git a/main/src/main.rs b/main/src/main.rs index 630cf5c..44d0c8b 100644 --- a/main/src/main.rs +++ b/main/src/main.rs @@ -22,7 +22,7 @@ use tracing_subscriber::{fmt, prelude::*, EnvFilter}; use tokio::task::LocalSet; #[tokio::main] -async fn main() -> Result<(), Box> { +async fn main() -> anyhow::Result<()> { // Set up tracing tracing_subscriber::registry() .with(fmt::layer().with_writer(std::io::stderr)) @@ -118,7 +118,7 @@ async fn main() -> Result<(), Box> { embedding_provider.clone(), None, ) - .await?; + .await; let api_state = ApiState::new(&config, storage.clone()).await?; @@ -295,8 +295,7 @@ mod tests { embedding_provider, None, ) - .await - .expect("failed to build html state"); + .await; let api_state = ApiState { db: db.clone(), diff --git a/main/src/server.rs b/main/src/server.rs index 4df3868..540f1a2 100644 --- a/main/src/server.rs +++ b/main/src/server.rs @@ -12,7 +12,7 @@ use tracing::info; use tracing_subscriber::{fmt, prelude::*, EnvFilter}; #[tokio::main(flavor = "multi_thread", worker_threads = 2)] -async fn main() -> Result<(), Box> { +async fn main() -> anyhow::Result<()> { // Set up tracing tracing_subscriber::registry() .with(fmt::layer().with_writer(std::io::stderr)) @@ -73,7 +73,7 @@ async fn main() -> Result<(), Box> { embedding_provider, None, ) - .await?; + .await; let api_state = ApiState::new(&config, storage).await?; diff --git a/main/src/worker.rs b/main/src/worker.rs index 33f2f17..9a29a56 100644 --- a/main/src/worker.rs +++ b/main/src/worker.rs @@ -11,7 +11,7 @@ use tracing::info; use tracing_subscriber::{fmt, prelude::*, EnvFilter}; #[tokio::main] -async fn main() -> Result<(), Box> { +async fn main() -> anyhow::Result<()> { // Set up tracing tracing_subscriber::registry() .with(fmt::layer())