flusso_query/error.rs
1//! The client's error type.
2
3use thiserror::Error;
4
5/// Anything that can go wrong building a request, talking to OpenSearch, or
6/// decoding a response.
7#[derive(Debug, Error)]
8#[non_exhaustive]
9pub enum Error {
10 /// The base URL handed to [`crate::Client::connect`] was not a usable
11 /// `http`/`https` URL.
12 #[error("invalid base url: {0}")]
13 Url(String),
14
15 /// The underlying HTTP transport failed (connection, timeout, TLS, …).
16 #[error("http transport error: {0}")]
17 Http(#[from] reqwest::Error),
18
19 /// OpenSearch answered with a non-success status. `body` is the raw payload,
20 /// captured for diagnostics.
21 #[error("opensearch returned status {status}: {body}")]
22 Status {
23 /// The HTTP status code.
24 status: u16,
25 /// The response body, as text.
26 body: String,
27 },
28
29 /// One slot of a [`crate::Client::msearch`] bundle failed. `_msearch`
30 /// reports errors per slot; the whole call fails on the first one — there
31 /// are no partial results.
32 #[error("msearch slot {slot} failed (status {status}): {body}")]
33 Msearch {
34 /// Zero-based position of the failed search in the bundle.
35 slot: usize,
36 /// The per-slot status OpenSearch reported (`0` if absent).
37 status: u16,
38 /// The slot's error object, serialized for diagnostics.
39 body: String,
40 },
41
42 /// A combined-search hit came from an index no
43 /// [`FlussoMultiDocument`](crate::FlussoMultiDocument) variant claims.
44 #[error("combined-search hit from unexpected index `{index}`")]
45 UnexpectedIndex {
46 /// The physical index name the hit reported.
47 index: String,
48 },
49
50 /// A response could not be decoded into the expected shape.
51 #[error("decoding response: {0}")]
52 Decode(#[from] serde_json::Error),
53}
54
55/// A `Result` whose error is this crate's [`Error`](enum@Error).
56pub type Result<T> = std::result::Result<T, Error>;