1use sift_query_core::{ParamError, PlanError};
2use thiserror::Error;
3
4use crate::ExtensionError;
5
6#[derive(Debug, Clone, PartialEq, Eq, Error)]
7#[non_exhaustive]
8pub enum RenderError {
9 #[error("query plan references unknown field id {0}")]
10 UnknownField(u16),
11 #[error("field {0} has no result alias")]
12 MissingAlias(String),
13 #[error("condition {0} has invalid values")]
14 InvalidCondition(String),
15 #[error("PostgreSQL binding is not implemented for {0}")]
16 UnsupportedBindType(String),
17 #[error("query target cannot be rendered by this operation")]
18 WrongTarget,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Error)]
22#[error("failed to decode column {column}: {reason}")]
23pub struct DecodeError {
24 pub column: String,
25 pub reason: String,
26}
27
28#[derive(Debug, Clone, PartialEq, Eq, Error)]
29#[error("schema result contract failed for {entity}: {details}")]
30pub struct SchemaValidationError {
31 pub entity: &'static str,
32 pub details: String,
33}
34
35#[derive(Debug, Clone, Copy, PartialEq, Eq)]
36pub enum TimeoutStage {
37 PoolAcquire,
38 SchemaValidation,
39 ListQuery,
40 ClusterQuery,
41 Scan,
42 Export,
43 Enrichment,
44}
45
46impl std::fmt::Display for TimeoutStage {
47 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48 formatter.write_str(match self {
49 Self::PoolAcquire => "pool acquire",
50 Self::SchemaValidation => "schema validation",
51 Self::ListQuery => "list query",
52 Self::ClusterQuery => "cluster query",
53 Self::Scan => "scan",
54 Self::Export => "export",
55 Self::Enrichment => "enrichment",
56 })
57 }
58}
59
60#[derive(Debug, Error)]
61#[non_exhaustive]
62pub enum PgSearchError {
63 #[error(transparent)]
64 Param(#[from] ParamError),
65 #[error(transparent)]
66 Plan(#[from] PlanError),
67 #[error(transparent)]
68 Render(#[from] RenderError),
69 #[error("failed to encode PostgreSQL arguments: {0}")]
70 Bind(String),
71 #[error("parallel execution gate is closed")]
72 ParallelGateClosed,
73 #[error(transparent)]
74 Sql(#[from] sqlx::Error),
75 #[error(transparent)]
76 Decode(#[from] DecodeError),
77 #[error(transparent)]
78 Extension(#[from] ExtensionError),
79 #[error("query timed out during {0}")]
80 Timeout(TimeoutStage),
81 #[error("scan exceeded its maximum row budget of {max_rows}")]
82 ScanLimitExceeded { max_rows: u32 },
83 #[error("external PostgreSQL execution only supports SequentialBestEffort")]
84 ExternalExecutionStrategy,
85 #[error("scan waiting queue is full")]
86 ScanQueueFull,
87 #[error("CSV output failed")]
88 ExportIo(#[source] std::io::Error),
89 #[error(transparent)]
90 SchemaValidation(#[from] SchemaValidationError),
91}