Spaces:
Runtime error
Runtime error
Zsombor Gegesy
commited on
Commit
•
f56002d
1
Parent(s):
8ed4c9e
Rename the error to NoSuchEngineFound and add the name of missing engine to it
Browse files
src/models/aggregation_models.rs
CHANGED
@@ -85,14 +85,14 @@ impl EngineErrorInfo {
|
|
85 |
pub fn new(error: &EngineError, engine: &str) -> Self {
|
86 |
Self {
|
87 |
error: match error {
|
88 |
-
EngineError::
|
89 |
EngineError::RequestError => "RequestError".to_owned(),
|
90 |
EngineError::EmptyResultSet => "EmptyResultSet".to_owned(),
|
91 |
EngineError::UnexpectedError => "UnexpectedError".to_owned(),
|
92 |
},
|
93 |
engine: engine.to_owned(),
|
94 |
severity_color: match error {
|
95 |
-
EngineError::
|
96 |
EngineError::RequestError => "green".to_owned(),
|
97 |
EngineError::EmptyResultSet => "blue".to_owned(),
|
98 |
EngineError::UnexpectedError => "red".to_owned(),
|
|
|
85 |
pub fn new(error: &EngineError, engine: &str) -> Self {
|
86 |
Self {
|
87 |
error: match error {
|
88 |
+
EngineError::NoSuchEngineFound(_) => "EngineNotFound".to_owned(),
|
89 |
EngineError::RequestError => "RequestError".to_owned(),
|
90 |
EngineError::EmptyResultSet => "EmptyResultSet".to_owned(),
|
91 |
EngineError::UnexpectedError => "UnexpectedError".to_owned(),
|
92 |
},
|
93 |
engine: engine.to_owned(),
|
94 |
severity_color: match error {
|
95 |
+
EngineError::NoSuchEngineFound(_) => "red".to_owned(),
|
96 |
EngineError::RequestError => "green".to_owned(),
|
97 |
EngineError::EmptyResultSet => "blue".to_owned(),
|
98 |
EngineError::UnexpectedError => "red".to_owned(),
|
src/models/engine_models.rs
CHANGED
@@ -9,7 +9,7 @@ use std::{collections::HashMap, fmt, time::Duration};
|
|
9 |
#[derive(Debug)]
|
10 |
pub enum EngineError {
|
11 |
/// No matching engine found
|
12 |
-
|
13 |
/// This variant handles all request related errors like forbidden, not found,
|
14 |
/// etc.
|
15 |
EmptyResultSet,
|
@@ -26,8 +26,8 @@ pub enum EngineError {
|
|
26 |
impl fmt::Display for EngineError {
|
27 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
28 |
match self {
|
29 |
-
EngineError::
|
30 |
-
write!(f, "
|
31 |
}
|
32 |
EngineError::EmptyResultSet => {
|
33 |
write!(f, "The upstream search engine returned an empty result set")
|
@@ -150,7 +150,11 @@ impl EngineHandler {
|
|
150 |
let engine = crate::engines::searx::Searx::new()?;
|
151 |
("searx", Box::new(engine))
|
152 |
}
|
153 |
-
_ =>
|
|
|
|
|
|
|
|
|
154 |
};
|
155 |
|
156 |
Ok(Self {
|
|
|
9 |
#[derive(Debug)]
|
10 |
pub enum EngineError {
|
11 |
/// No matching engine found
|
12 |
+
NoSuchEngineFound(String),
|
13 |
/// This variant handles all request related errors like forbidden, not found,
|
14 |
/// etc.
|
15 |
EmptyResultSet,
|
|
|
26 |
impl fmt::Display for EngineError {
|
27 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
28 |
match self {
|
29 |
+
EngineError::NoSuchEngineFound(engine) => {
|
30 |
+
write!(f, "No such engine with the name '{engine}' found")
|
31 |
}
|
32 |
EngineError::EmptyResultSet => {
|
33 |
write!(f, "The upstream search engine returned an empty result set")
|
|
|
150 |
let engine = crate::engines::searx::Searx::new()?;
|
151 |
("searx", Box::new(engine))
|
152 |
}
|
153 |
+
_ => {
|
154 |
+
return Err(Report::from(EngineError::NoSuchEngineFound(
|
155 |
+
engine_name.to_string(),
|
156 |
+
)))
|
157 |
+
}
|
158 |
};
|
159 |
|
160 |
Ok(Self {
|