1use thiserror::Error;
2
3#[derive(Debug, Error)]
7pub enum ScoutError {
8 #[error("invalid index name `{0}`: must be non-empty, contain no whitespace, contain no '/', and not start with '.'")]
9 InvalidIndexName(String),
10 #[error("invalid search result: {0}")]
11 InvalidResult(String),
12 #[error("unsupported operation: {0}")]
13 Unsupported(String),
14 #[error("JSON error: {0}")]
15 Json(#[from] serde_json::Error),
16 #[cfg(any(
17 feature = "elasticsearch",
18 feature = "meilisearch",
19 feature = "typesense",
20 feature = "algolia"
21 ))]
22 #[error("HTTP request failed: {0}")]
23 Http(#[from] reqwest::Error),
24 #[cfg(feature = "database")]
25 #[error("SQLite error: {0}")]
26 Sqlx(#[from] sqlx::Error),
27 #[cfg(any(
28 feature = "elasticsearch",
29 feature = "meilisearch",
30 feature = "typesense",
31 feature = "algolia",
32 feature = "xunsearch"
33 ))]
34 #[error("backend engine request failed: {0}")]
35 Backend(String),
36 #[cfg(feature = "xunsearch")]
37 #[error("xunsearch error: {0}")]
38 XunSearch(String),
39 #[cfg(feature = "xunsearch")]
40 #[error("xunsearch I/O error: {0}")]
41 XunSearchIo(#[from] std::io::Error),
42}
43
44impl ScoutError {
45 pub fn pet_hint(&self) -> &'static str {
51 crate::pet::hint(self)
52 }
53}
54
55pub type Result<T> = std::result::Result<T, ScoutError>;