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