From f56002dca67a0213981f3948b850d3dba8343d69 Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Sun, 8 Oct 2023 22:30:31 +0200 Subject: [PATCH] Rename the error to NoSuchEngineFound and add the name of missing engine to it --- src/models/aggregation_models.rs | 4 ++-- src/models/engine_models.rs | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/models/aggregation_models.rs b/src/models/aggregation_models.rs index 6e4bddf..660804e 100644 --- a/src/models/aggregation_models.rs +++ b/src/models/aggregation_models.rs @@ -85,14 +85,14 @@ impl EngineErrorInfo { pub fn new(error: &EngineError, engine: &str) -> Self { Self { error: match error { - EngineError::EngineNotFound => "EngineNotFound".to_owned(), + EngineError::NoSuchEngineFound(_) => "EngineNotFound".to_owned(), EngineError::RequestError => "RequestError".to_owned(), EngineError::EmptyResultSet => "EmptyResultSet".to_owned(), EngineError::UnexpectedError => "UnexpectedError".to_owned(), }, engine: engine.to_owned(), severity_color: match error { - EngineError::EngineNotFound => "red".to_owned(), + EngineError::NoSuchEngineFound(_) => "red".to_owned(), EngineError::RequestError => "green".to_owned(), EngineError::EmptyResultSet => "blue".to_owned(), EngineError::UnexpectedError => "red".to_owned(), diff --git a/src/models/engine_models.rs b/src/models/engine_models.rs index d53fc0c..05b5a11 100644 --- a/src/models/engine_models.rs +++ b/src/models/engine_models.rs @@ -9,7 +9,7 @@ use std::{collections::HashMap, fmt, time::Duration}; #[derive(Debug)] pub enum EngineError { /// No matching engine found - EngineNotFound, + NoSuchEngineFound(String), /// This variant handles all request related errors like forbidden, not found, /// etc. EmptyResultSet, @@ -26,8 +26,8 @@ pub enum EngineError { impl fmt::Display for EngineError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - EngineError::EngineNotFound => { - write!(f, "Search engine not found") + EngineError::NoSuchEngineFound(engine) => { + write!(f, "No such engine with the name '{engine}' found") } EngineError::EmptyResultSet => { write!(f, "The upstream search engine returned an empty result set") @@ -150,7 +150,11 @@ impl EngineHandler { let engine = crate::engines::searx::Searx::new()?; ("searx", Box::new(engine)) } - _ => return Err(Report::from(EngineError::EngineNotFound)), + _ => { + return Err(Report::from(EngineError::NoSuchEngineFound( + engine_name.to_string(), + ))) + } }; Ok(Self {