Skip to main content

reifydb_sub_server/
execute.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4//! Error types for query and command execution.
5//!
6//! The actual dispatch logic lives in [`crate::dispatch`]. This module
7//! only defines the shared error types used by all transport handlers.
8
9use std::{error, fmt, sync::Arc};
10
11use reifydb_type::error::Diagnostic;
12
13/// Error types for query/command execution.
14#[derive(Debug)]
15pub enum ExecuteError {
16	/// Query exceeded the configured timeout.
17	Timeout,
18	/// Query was cancelled.
19	Cancelled,
20	/// Stream disconnected unexpectedly.
21	Disconnected,
22	/// Database engine returned an error with full diagnostic info.
23	Engine {
24		/// The full diagnostic with error code, source location, help text, etc.
25		diagnostic: Arc<Diagnostic>,
26		/// The RQL that caused the error.
27		rql: String,
28	},
29	/// Request was rejected by a request interceptor.
30	Rejected {
31		/// Error code for the rejection (e.g. "AUTH_REQUIRED", "INSUFFICIENT_CREDITS").
32		code: String,
33		/// Human-readable reason for rejection.
34		message: String,
35	},
36}
37
38impl fmt::Display for ExecuteError {
39	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40		match self {
41			ExecuteError::Timeout => write!(f, "Query execution timed out"),
42			ExecuteError::Cancelled => write!(f, "Query was cancelled"),
43			ExecuteError::Disconnected => write!(f, "Query stream disconnected unexpectedly"),
44			ExecuteError::Engine {
45				diagnostic,
46				..
47			} => write!(f, "Engine error: {}", diagnostic.message),
48			ExecuteError::Rejected {
49				code,
50				message,
51			} => write!(f, "Rejected [{}]: {}", code, message),
52		}
53	}
54}
55
56impl error::Error for ExecuteError {}
57
58/// Result type for execute operations.
59pub type ExecuteResult<T> = Result<T, ExecuteError>;