vlorql_core/errors/mod.rs
1//! Structured, machine-readable errors for the VlorQl core.
2//!
3//! Every error keeps both a typed error kind and a JSON `details` payload. The
4//! typed kind is useful to Rust callers, while the payload allows callers to
5//! preserve additional context without parsing an error string.
6
7mod kinds;
8mod validation;
9mod vlorql_error;
10
11pub use kinds::{
12 AuditErrorKind, CompilationErrorKind, ConfigErrorKind, LlmErrorKind, PolicyErrorKind,
13 SchemaErrorKind, ValidationErrorKind,
14};
15
16pub use vlorql_error::{
17 CompilationError, ConfigError, LlmError, PolicyError, SchemaError, ValidationError, VlorQLError,
18};
19
20pub use validation::{ValidationErrors, validate};
21
22use serde::{Deserialize, Serialize};
23use serde_json::Value;
24
25/// The response shape exposed by API and LLM-facing layers.
26///
27/// # Examples
28///
29/// ```
30/// use vlorql_core::errors::ErrorResponse;
31/// use serde_json::json;
32///
33/// let response = ErrorResponse {
34/// code: "V001".to_owned(),
35/// message: "validation error".to_owned(),
36/// details: json!({"field": "from"}),
37/// suggestion: Some("add a from clause".to_owned()),
38/// };
39/// assert_eq!(response.code, "V001");
40/// ```
41#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
42pub struct ErrorResponse {
43 /// Stable machine-readable error code.
44 pub code: String,
45 /// Human-readable description of the error.
46 pub message: String,
47 /// Structured context associated with the error.
48 pub details: Value,
49 /// Optional guidance that can be used to repair the request.
50 pub suggestion: Option<String>,
51}