Skip to main content

reifydb_sub_server/
execute.rs

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