From 9b65e40952046db617d1c0b8b1ab44c33e854098 Mon Sep 17 00:00:00 2001 From: senke Date: Thu, 12 Feb 2026 23:33:02 +0100 Subject: [PATCH] fix(chat): resolve compilation errors and clean all warnings - Replace ChatError::AuthError (nonexistent variant) with InvalidToken and ServiceUnavailable in jwt_manager.rs - Remove unused imports: ExchangeDeclareOptions, ExchangeKind (event_bus), StatusCode (request_id), warn (typing_indicator), AsyncCommands (rate_limiter) - Fix unnecessary mut: delivered_status.rs, read_receipts.rs - Prefix unused struct fields: _config, _connection (event_bus), _secret (csrf) - Prefix unused variables: _metadata, parent_message_id: _ (handler.rs), user_id: _ (permission.rs) - Allow dead_code on GetMessagesQuery and exchange_kind_from_str Chat server now compiles with zero errors and zero warnings. Co-authored-by: Cursor --- veza-chat-server/src/delivered_status.rs | 2 +- veza-chat-server/src/event_bus.rs | 18 ++++++++---------- veza-chat-server/src/jwt_manager.rs | 13 +++++++------ veza-chat-server/src/main.rs | 1 + veza-chat-server/src/middleware/request_id.rs | 2 +- veza-chat-server/src/read_receipts.rs | 2 +- veza-chat-server/src/security/csrf.rs | 4 ++-- veza-chat-server/src/security/permission.rs | 2 +- veza-chat-server/src/security/rate_limiter.rs | 2 -- veza-chat-server/src/typing_indicator.rs | 2 +- veza-chat-server/src/websocket/handler.rs | 4 ++-- 11 files changed, 25 insertions(+), 27 deletions(-) diff --git a/veza-chat-server/src/delivered_status.rs b/veza-chat-server/src/delivered_status.rs index ccaba48c0..86255b876 100644 --- a/veza-chat-server/src/delivered_status.rs +++ b/veza-chat-server/src/delivered_status.rs @@ -54,7 +54,7 @@ impl DeliveredStatusManager { .fetch_optional(&self.pool) .await?; - if let Some(mut status) = existing { + if let Some(status) = existing { // Mettre à jour le timestamp de délivrance let updated = sqlx::query_as::<_, DeliveredStatus>( "UPDATE delivered_status diff --git a/veza-chat-server/src/event_bus.rs b/veza-chat-server/src/event_bus.rs index ff1396aa7..4935106d9 100644 --- a/veza-chat-server/src/event_bus.rs +++ b/veza-chat-server/src/event_bus.rs @@ -1,7 +1,4 @@ -use lapin::{ - options::ExchangeDeclareOptions, types::FieldTable, Channel, Connection, ConnectionProperties, - ExchangeKind, -}; +use lapin::{types::FieldTable, Channel, Connection, ConnectionProperties}; use tokio::time::{sleep, Duration}; use tracing::{error, info, warn}; @@ -27,8 +24,8 @@ impl EventBusUnavailableError { /// Gestionnaire de connexion RabbitMQ pub struct RabbitMQEventBus { - config: config::RabbitMQConfig, // Use the canonical config type - connection: Option, + _config: config::RabbitMQConfig, // Use the canonical config type + _connection: Option, channel: Option, pub is_enabled: bool, } @@ -39,8 +36,8 @@ impl RabbitMQEventBus { if !config.enable { info!("📴 EventBus RabbitMQ désactivé par configuration."); return Ok(Self { - config, - connection: None, + _config: config, + _connection: None, channel: None, is_enabled: false, }); @@ -65,8 +62,8 @@ impl RabbitMQEventBus { ChatError::internal_error(format!("Failed to open RabbitMQ channel: {}", e)) })?; return Ok(Self { - config, - connection: Some(conn), + _config: config, + _connection: Some(conn), channel: Some(channel), is_enabled: true, }); @@ -196,6 +193,7 @@ impl RabbitMQEventBus { }) } + #[allow(dead_code)] fn exchange_kind_from_str(s: &str) -> lapin::ExchangeKind { match s.to_lowercase().as_str() { "direct" => lapin::ExchangeKind::Direct, diff --git a/veza-chat-server/src/jwt_manager.rs b/veza-chat-server/src/jwt_manager.rs index 33dd40763..82b8e19f1 100644 --- a/veza-chat-server/src/jwt_manager.rs +++ b/veza-chat-server/src/jwt_manager.rs @@ -411,9 +411,9 @@ impl JwtManager { user_id = %claims.user_id, "User not found in DB during token refresh — rejecting token" ); - return Err(ChatError::AuthError( - "User no longer exists — token refresh denied".to_string(), - )); + return Err(ChatError::InvalidToken { + reason: "User no longer exists — token refresh denied".to_string(), + }); } } } else { @@ -421,9 +421,10 @@ impl JwtManager { user_id = %claims.user_id, "No DB pool available for token refresh — rejecting token" ); - return Err(ChatError::AuthError( - "Database unavailable — token refresh denied".to_string(), - )); + return Err(ChatError::ServiceUnavailable { + service: "database".to_string(), + reason: "Database unavailable — token refresh denied".to_string(), + }); }; // MIGRATION UUID: Cloner user_id avant de le move diff --git a/veza-chat-server/src/main.rs b/veza-chat-server/src/main.rs index aedd156b6..38fc1c0a5 100644 --- a/veza-chat-server/src/main.rs +++ b/veza-chat-server/src/main.rs @@ -55,6 +55,7 @@ struct SendMessageRequest { /// Paramètres de récupération de messages #[derive(Deserialize)] +#[allow(dead_code)] struct GetMessagesQuery { conversation_id: Uuid, limit: Option, diff --git a/veza-chat-server/src/middleware/request_id.rs b/veza-chat-server/src/middleware/request_id.rs index c36301916..e80c22f89 100644 --- a/veza-chat-server/src/middleware/request_id.rs +++ b/veza-chat-server/src/middleware/request_id.rs @@ -3,7 +3,7 @@ use axum::{ extract::Request, - http::{HeaderMap, HeaderName, HeaderValue, StatusCode}, + http::{HeaderMap, HeaderName, HeaderValue}, middleware::Next, response::Response, }; diff --git a/veza-chat-server/src/read_receipts.rs b/veza-chat-server/src/read_receipts.rs index ca2d3e503..2d3592c0d 100644 --- a/veza-chat-server/src/read_receipts.rs +++ b/veza-chat-server/src/read_receipts.rs @@ -83,7 +83,7 @@ impl ReadReceiptManager { .fetch_optional(&self.pool) .await?; - if let Some(mut receipt) = existing { + if let Some(receipt) = existing { // Mettre à jour le timestamp de lecture let updated = sqlx::query_as::<_, ReadReceipt>( "UPDATE read_receipts diff --git a/veza-chat-server/src/security/csrf.rs b/veza-chat-server/src/security/csrf.rs index 643e90faf..3f17f7366 100644 --- a/veza-chat-server/src/security/csrf.rs +++ b/veza-chat-server/src/security/csrf.rs @@ -47,7 +47,7 @@ pub struct CsrfManager { /// Tokens CSRF actifs (jti -> session_id) active_tokens: Arc>>, /// Configuration - secret: String, + _secret: String, /// Durée de vie des tokens CSRF (en secondes) token_lifetime: i64, } @@ -69,7 +69,7 @@ impl CsrfManager { decoding_key, validation, active_tokens: Arc::new(RwLock::new(HashMap::new())), - secret, + _secret: secret, token_lifetime, }) } diff --git a/veza-chat-server/src/security/permission.rs b/veza-chat-server/src/security/permission.rs index 3af931205..30489d8dc 100644 --- a/veza-chat-server/src/security/permission.rs +++ b/veza-chat-server/src/security/permission.rs @@ -51,7 +51,7 @@ impl From for ChatError { fn from(err: PermissionError) -> Self { match err { PermissionError::NotMember { - user_id, + user_id: _, conversation_id, } => ChatError::NotMember { conversation_id: conversation_id.to_string(), diff --git a/veza-chat-server/src/security/rate_limiter.rs b/veza-chat-server/src/security/rate_limiter.rs index 25c200317..ebf60cd3e 100644 --- a/veza-chat-server/src/security/rate_limiter.rs +++ b/veza-chat-server/src/security/rate_limiter.rs @@ -165,8 +165,6 @@ impl RateLimiter { action: &RateLimitAction, config: &RateLimitConfig, ) -> Result { - use redis::AsyncCommands; - let key = format!("rl:chat:{}:{}", user_id, action.redis_key_suffix()); let window_secs = config.window.as_secs().max(1); diff --git a/veza-chat-server/src/typing_indicator.rs b/veza-chat-server/src/typing_indicator.rs index 574b4c544..0440b16a0 100644 --- a/veza-chat-server/src/typing_indicator.rs +++ b/veza-chat-server/src/typing_indicator.rs @@ -2,7 +2,7 @@ use chrono::{Duration, Utc}; use std::collections::HashMap; use std::sync::Arc; use tokio::sync::RwLock; -use tracing::{debug, info, instrument, warn}; +use tracing::{debug, info, instrument}; use uuid::Uuid; /// Représente un changement de statut typing pour un utilisateur diff --git a/veza-chat-server/src/websocket/handler.rs b/veza-chat-server/src/websocket/handler.rs index c8f3f0d4c..7166998c1 100644 --- a/veza-chat-server/src/websocket/handler.rs +++ b/veza-chat-server/src/websocket/handler.rs @@ -305,7 +305,7 @@ async fn handle_incoming_message( IncomingMessage::SendMessage { conversation_id, content, - parent_message_id, + parent_message_id: _, attachments, } => { info!( @@ -333,7 +333,7 @@ async fn handle_incoming_message( })?; // Préparer les métadonnées pour les pièces jointes - let metadata = attachments.as_ref().map(|a| serde_json::to_value(a).unwrap_or(serde_json::Value::Null)); + let _metadata = attachments.as_ref().map(|a| serde_json::to_value(a).unwrap_or(serde_json::Value::Null)); // Enregistrer le message dans le store // Note: On pourrait étendre MessageRepository::create pour accepter metadata et parent_message_id