Skip to main content

reifydb_core/error/diagnostic/
engine.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use reifydb_type::{error::Diagnostic, fragment::Fragment};
5
6/// General frame processing error
7pub fn frame_error(message: String) -> Diagnostic {
8	Diagnostic {
9		code: "ENG_001".to_string(),
10		statement: None,
11		message: format!("Frame processing error: {}", message),
12		column: None,
13		fragment: Fragment::None,
14		label: None,
15		help: Some("Check frame data and operations".to_string()),
16		notes: vec![],
17		cause: None,
18		operator_chain: None,
19	}
20}
21
22/// Column policy saturation error - wraps an existing diagnostic
23pub fn saturation_error(diagnostic: Diagnostic) -> Diagnostic {
24	let statement = diagnostic.statement.clone();
25	let message = diagnostic.message.clone();
26	let column = diagnostic.column.clone();
27	let fragment = diagnostic.fragment.clone();
28	let label = diagnostic.label.clone();
29	let notes = diagnostic.notes.clone();
30
31	Diagnostic {
32		code: "ENG_002".to_string(),
33		statement,
34		message: format!("Column policy saturation: {}", message),
35		column,
36		fragment,
37		label,
38		help: Some("Adjust column policy constraints".to_string()),
39		notes,
40		cause: Some(Box::new(diagnostic)),
41		operator_chain: None,
42	}
43}
44
45/// Frame missing required ROW_NUMBER column error
46pub fn missing_row_number_column() -> Diagnostic {
47	Diagnostic {
48		code: "ENG_003".to_string(),
49		statement: None,
50		message: "Frame must have a __ROW__ID__ column for UPDATE operations".to_string(),
51		column: None,
52		fragment: Fragment::None,
53		label: Some("missing required column".to_string()),
54		help: Some("Ensure the query includes the encoded ID in the result set".to_string()),
55		notes: vec!["UPDATE operations require encoded identifiers to locate existing rows".to_string()],
56		cause: None,
57		operator_chain: None,
58	}
59}
60
61/// Invalid or undefined RowNumber values error
62pub fn invalid_row_number_values() -> Diagnostic {
63	Diagnostic {
64		code: "ENG_004".to_string(),
65		statement: None,
66		message: "All RowNumber values must be defined for UPDATE operations".to_string(),
67		column: None,
68		fragment: Fragment::None,
69		label: Some("invalid encoded identifiers".to_string()),
70		help: Some("Check that the input data contains valid encoded IDs".to_string()),
71		notes: vec!["RowNumber column must contain valid identifiers, not none values".to_string()],
72		cause: None,
73		operator_chain: None,
74	}
75}
76
77/// Invalid parameter reference error
78pub fn invalid_parameter_reference(fragment: Fragment) -> Diagnostic {
79	let value = fragment.text();
80	Diagnostic {
81		code: "ENG_005".to_string(),
82		statement: None,
83		message: format!("Invalid parameter reference: {}", value),
84		column: None,
85		fragment,
86		label: Some("invalid parameter syntax".to_string()),
87		help: Some("Use $1, $2 for positional parameters or $name for named parameters".to_string()),
88		notes: vec![],
89		cause: None,
90		operator_chain: None,
91	}
92}
93
94/// Parameter not found error
95pub fn parameter_not_found(fragment: Fragment) -> Diagnostic {
96	let value = fragment.text();
97	Diagnostic {
98		code: "ENG_006".to_string(),
99		statement: None,
100		message: format!("Parameter not found: {}", value),
101		column: None,
102		fragment,
103		label: Some("parameter not provided".to_string()),
104		help: Some("Ensure all referenced parameters are provided in the query call".to_string()),
105		notes: vec![],
106		cause: None,
107		operator_chain: None,
108	}
109}