From 94b845eb5b4de955eb7fd7c4a7a3f75c7479f56f Mon Sep 17 00:00:00 2001 From: Siavash Sameni Date: Thu, 26 Mar 2026 22:16:11 +0400 Subject: [PATCH] Fix all compiler warnings across server and client - Remove unused ServerConfig struct (config via CLI args) - Remove unused otpks field from Database (not yet needed) - Wire AppError into message routes with proper error propagation - Remove unused imports in send.rs (Seed, MessageContent, etc.) - Suppress dead_code on BundleResponse.fingerprint (needed by serde) Zero warnings, 17/17 tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) --- warzone/crates/warzone-client/src/cli/send.rs | 4 +-- warzone/crates/warzone-client/src/net.rs | 1 + warzone/crates/warzone-server/src/config.rs | 6 ++-- warzone/crates/warzone-server/src/db.rs | 3 -- warzone/crates/warzone-server/src/errors.rs | 5 +++ .../warzone-server/src/routes/messages.rs | 35 +++++++++---------- 6 files changed, 25 insertions(+), 29 deletions(-) diff --git a/warzone/crates/warzone-client/src/cli/send.rs b/warzone/crates/warzone-client/src/cli/send.rs index a1adf1f..ad8d8d3 100644 --- a/warzone/crates/warzone-client/src/cli/send.rs +++ b/warzone/crates/warzone-client/src/cli/send.rs @@ -1,8 +1,6 @@ use anyhow::{Context, Result}; -use warzone_protocol::identity::Seed; -use warzone_protocol::message::{MessageContent, MessageType, WarzoneMessage}; use warzone_protocol::ratchet::{RatchetMessage, RatchetState}; -use warzone_protocol::types::{Fingerprint, MessageId, SessionId}; +use warzone_protocol::types::Fingerprint; use warzone_protocol::x3dh; use x25519_dalek::PublicKey; diff --git a/warzone/crates/warzone-client/src/net.rs b/warzone/crates/warzone-client/src/net.rs index ff34089..4b754ec 100644 --- a/warzone/crates/warzone-client/src/net.rs +++ b/warzone/crates/warzone-client/src/net.rs @@ -23,6 +23,7 @@ struct SendRequest { } #[derive(Deserialize)] +#[allow(dead_code)] struct BundleResponse { fingerprint: String, bundle: String, // base64 diff --git a/warzone/crates/warzone-server/src/config.rs b/warzone/crates/warzone-server/src/config.rs index 372f47a..99a4e03 100644 --- a/warzone/crates/warzone-server/src/config.rs +++ b/warzone/crates/warzone-server/src/config.rs @@ -1,4 +1,2 @@ -pub struct ServerConfig { - pub bind_addr: String, - pub data_dir: String, -} +// Server configuration — currently handled via CLI args in main.rs. +// This module will be used when file-based configuration is added. diff --git a/warzone/crates/warzone-server/src/db.rs b/warzone/crates/warzone-server/src/db.rs index aa05200..afbc796 100644 --- a/warzone/crates/warzone-server/src/db.rs +++ b/warzone/crates/warzone-server/src/db.rs @@ -3,7 +3,6 @@ use anyhow::Result; pub struct Database { pub keys: sled::Tree, pub messages: sled::Tree, - pub otpks: sled::Tree, _db: sled::Db, } @@ -12,11 +11,9 @@ impl Database { let db = sled::open(data_dir)?; let keys = db.open_tree("keys")?; let messages = db.open_tree("messages")?; - let otpks = db.open_tree("otpks")?; Ok(Database { keys, messages, - otpks, _db: db, }) } diff --git a/warzone/crates/warzone-server/src/errors.rs b/warzone/crates/warzone-server/src/errors.rs index ffd398f..ebba617 100644 --- a/warzone/crates/warzone-server/src/errors.rs +++ b/warzone/crates/warzone-server/src/errors.rs @@ -1,10 +1,12 @@ use axum::http::StatusCode; use axum::response::{IntoResponse, Response}; +/// Wraps anyhow::Error into an axum-compatible error response. pub struct AppError(pub anyhow::Error); impl IntoResponse for AppError { fn into_response(self) -> Response { + tracing::error!("{:#}", self.0); (StatusCode::INTERNAL_SERVER_ERROR, self.0.to_string()).into_response() } } @@ -14,3 +16,6 @@ impl> From for AppError { AppError(err.into()) } } + +/// Convenience type for route handlers. +pub type AppResult = Result; diff --git a/warzone/crates/warzone-server/src/routes/messages.rs b/warzone/crates/warzone-server/src/routes/messages.rs index a46e2de..8d3818b 100644 --- a/warzone/crates/warzone-server/src/routes/messages.rs +++ b/warzone/crates/warzone-server/src/routes/messages.rs @@ -5,6 +5,7 @@ use axum::{ }; use serde::Deserialize; +use crate::errors::AppResult; use crate::state::AppState; pub fn routes() -> Router { @@ -17,45 +18,41 @@ pub fn routes() -> Router { #[derive(Deserialize)] struct SendRequest { to: String, - message: Vec, // bincode-serialized WarzoneMessage + message: Vec, } async fn send_message( State(state): State, Json(req): Json, -) -> Json { - // Append to recipient's queue +) -> AppResult> { let key = format!("queue:{}", req.to); - let _ = state.db.messages.insert( + state.db.messages.insert( format!("{}:{}", key, uuid::Uuid::new_v4()).as_bytes(), req.message, - ); - Json(serde_json::json!({ "ok": true })) + )?; + Ok(Json(serde_json::json!({ "ok": true }))) } async fn poll_messages( State(state): State, Path(fingerprint): Path, -) -> Json> { +) -> AppResult>> { let prefix = format!("queue:{}", fingerprint); let mut messages = Vec::new(); for item in state.db.messages.scan_prefix(prefix.as_bytes()) { - if let Ok((_, value)) = item { - messages.push(base64::Engine::encode( - &base64::engine::general_purpose::STANDARD, - &value, - )); - } + let (_, value) = item?; + messages.push(base64::Engine::encode( + &base64::engine::general_purpose::STANDARD, + &value, + )); } - Json(messages) + Ok(Json(messages)) } async fn ack_message( State(state): State, Path(id): Path, -) -> Json { - // Scan for and remove the message with this ID - // In a real implementation, we'd have a proper index - let _ = state.db.messages.remove(id.as_bytes()); - Json(serde_json::json!({ "ok": true })) +) -> AppResult> { + state.db.messages.remove(id.as_bytes())?; + Ok(Json(serde_json::json!({ "ok": true }))) }