tellaro-query-language 3.0.0

A flexible, human-friendly query language for searching and filtering structured data
Documentation
//! Error types for OpenSearch operations.

use thiserror::Error;

/// Result type for OpenSearch operations
pub type Result<T> = std::result::Result<T, OpenSearchError>;

/// Errors that can occur during OpenSearch operations
#[derive(Error, Debug)]
pub enum OpenSearchError {
    /// Connection error
    #[error("OpenSearch connection error: {0}")]
    ConnectionError(String),

    /// Query translation error
    #[error("Query translation error: {0}")]
    TranslationError(String),

    /// Field mapping error
    #[error("Field mapping error: {0}")]
    MappingError(String),

    /// An operator cannot be applied to a field of this type.
    ///
    /// Mirrors Python's `TQLTypeError` (`src/tql/exceptions.py`). Rust used to
    /// have no equivalent: `get_query_field` always returned *some* field name,
    /// so `message gt 5` on a `text` field emitted a `range` query that
    /// OpenSearch answers with zero hits. Python refuses the same query and
    /// tells the operator why.
    ///
    /// Zero hits is the worst available answer here — it is indistinguishable
    /// from "nothing matched", which is exactly the confusion TQL exists to
    /// remove. Erroring is the whole point of an intelligent query layer: the
    /// user should not need to know that a `text` field cannot be range-queried,
    /// but they must be TOLD rather than silently given nothing.
    #[error(
        "Cannot apply operator '{operator}' to field '{field}' of type '{field_type}'.{suggestion}"
    )]
    TypeError {
        /// The field the operator was applied to.
        field: String,
        /// The field's mapped type.
        field_type: String,
        /// The operator that cannot be applied.
        operator: String,
        /// Actionable guidance, pre-formatted with a leading space (or empty).
        suggestion: String,
    },

    /// The operator is not supported for any of the field's available types.
    ///
    /// Mirrors Python's `TQLUnsupportedOperationError`.
    #[error("Operator '{operator}' is not supported for available field types: {available_types}")]
    UnsupportedOperation {
        /// The operator that could not be resolved onto a usable field.
        operator: String,
        /// What the field DOES offer, so the message is actionable.
        available_types: String,
    },

    /// Search execution error
    #[error("Search execution error: {0}")]
    SearchError(String),

    /// Configuration error
    #[error("Configuration error: {0}")]
    ConfigError(String),

    /// JSON serialization/deserialization error
    #[error("JSON error: {0}")]
    JsonError(#[from] serde_json::Error),

    /// OpenSearch client error
    #[error("OpenSearch client error: {0}")]
    ClientError(String),

    /// Post-processing error
    #[error("Post-processing error: {0}")]
    PostProcessingError(String),

    /// Scroll API error
    #[error("Scroll error: {0}")]
    ScrollError(String),

    /// TQL error (from main TQL crate)
    #[error("TQL error: {0}")]
    TqlError(#[from] crate::error::TqlError),
}

impl From<opensearch::Error> for OpenSearchError {
    fn from(err: opensearch::Error) -> Self {
        OpenSearchError::ClientError(err.to_string())
    }
}