Skip to main content

sift_query_core/
error.rs

1use thiserror::Error;
2
3/// Errors caused by untrusted query parameters or programmatic user queries.
4#[derive(Debug, Clone, PartialEq, Eq, Error)]
5#[non_exhaustive]
6pub enum ParamError {
7    #[error("query string exceeds the configured limit")]
8    QueryTooLong,
9    #[error("query string contains invalid form encoding")]
10    InvalidEncoding,
11    #[error("invalid parameter name: {0}")]
12    InvalidName(String),
13    #[error("unknown parameter: {0}")]
14    UnknownParameter(String),
15    #[error("unknown field: {0}")]
16    UnknownField(String),
17    #[error("duplicate parameter: {0}")]
18    DuplicateParameter(String),
19    #[error("conflicting parameters: {0}")]
20    ConflictingParameters(String),
21    #[error("indexed values for {field} are not contiguous at index {expected}")]
22    NonContiguousIndex { field: String, expected: usize },
23    #[error("operator {operator} for {field} expects {expected} value(s), got {actual}")]
24    WrongArity {
25        field: String,
26        operator: &'static str,
27        expected: &'static str,
28        actual: usize,
29    },
30    #[error("invalid value for field {field}: {reason}")]
31    InvalidValue { field: String, reason: String },
32    #[error("field is not filterable: {0}")]
33    NotFilterable(String),
34    #[error("field is not sortable: {0}")]
35    NotSortable(String),
36    #[error("field is not selectable: {0}")]
37    NotSelectable(String),
38    #[error("field access denied: {0}")]
39    FieldAccessDenied(String),
40    #[error("operator {operator} is not allowed for field {field}")]
41    OperatorNotAllowed {
42        field: String,
43        operator: &'static str,
44    },
45    #[error("ignore-case is not allowed for field {0}")]
46    IgnoreCaseNotAllowed(String),
47    #[error("dynamic projection is not allowed for this operation")]
48    ProjectionNotAllowed,
49    #[error("dynamic projection cannot be empty")]
50    EmptyProjection,
51    #[error("paging value is outside the configured range: {0}")]
52    PagingOutOfRange(String),
53    #[error("paging parameters are not allowed for this operation")]
54    PagingNotAllowed,
55    #[error("invalid group expression: {0}")]
56    InvalidGroupExpr(String),
57    #[error("group expression references an undefined group: {0}")]
58    UndefinedGroup(String),
59    #[error("defined group is not used by gexpr: {0}")]
60    UnusedGroup(String),
61    #[error("OR cannot combine WHERE and HAVING predicates")]
62    MixedPredicatePhase,
63    #[error("pagination requires a stable entity order")]
64    UnstablePagination,
65    #[error("DISTINCT ordering field is not part of the final projection: {0}")]
66    DistinctOrderNotProjected(String),
67    #[error("query exceeds the configured complexity budget: {0}")]
68    TooComplex(&'static str),
69}
70
71/// Errors in static entity or policy configuration.
72#[derive(Debug, Clone, PartialEq, Eq, Error)]
73#[non_exhaustive]
74pub enum ConfigError {
75    #[error("invalid configuration: {0}")]
76    Invalid(String),
77}
78
79/// Errors while combining a validated user query with server policy.
80#[derive(Debug, Clone, PartialEq, Eq, Error)]
81#[non_exhaustive]
82pub enum PlanError {
83    #[error(transparent)]
84    Param(#[from] ParamError),
85    #[error("query was built for a different entity schema")]
86    SchemaMismatch,
87}