Skip to main content

reifydb_engine/bulk_insert/
error.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
3
4//! Error types for bulk insert operations.
5
6use reifydb_type::{error::diagnostic::Diagnostic, fragment::Fragment};
7
8/// Bulk insert specific error codes and messages.
9pub struct BulkInsertError;
10
11impl BulkInsertError {
12	/// Error when a column name is not found in the target schema.
13	pub fn column_not_found(fragment: Fragment, source: &str, column: &str) -> reifydb_type::error::Error {
14		reifydb_type::error::Error(Diagnostic {
15			code: "BI_001".to_string(),
16			statement: None,
17			message: format!("column `{}` not found in `{}`", column, source),
18			fragment,
19			label: Some("unknown column".to_string()),
20			help: Some("check that the column name matches the schema".to_string()),
21			column: None,
22			notes: vec![],
23			cause: None,
24			operator_chain: None,
25		})
26	}
27
28	/// Error when there's a type mismatch between the value and column.
29	pub fn type_mismatch(
30		fragment: Fragment,
31		column: &str,
32		expected: &str,
33		actual: &str,
34	) -> reifydb_type::error::Error {
35		reifydb_type::error::Error(Diagnostic {
36			code: "BI_002".to_string(),
37			statement: None,
38			message: format!(
39				"type mismatch for column `{}`: expected `{}`, got `{}`",
40				column, expected, actual
41			),
42			fragment,
43			label: Some("incompatible type".to_string()),
44			help: Some("ensure the value type matches the column definition".to_string()),
45			column: None,
46			notes: vec![],
47			cause: None,
48			operator_chain: None,
49		})
50	}
51
52	/// Error when more values are provided than columns exist.
53	pub fn too_many_values(fragment: Fragment, expected: usize, actual: usize) -> reifydb_type::error::Error {
54		reifydb_type::error::Error(Diagnostic {
55			code: "BI_003".to_string(),
56			statement: None,
57			message: format!("too many values: expected {} columns, got {}", expected, actual),
58			fragment,
59			label: Some("value count mismatch".to_string()),
60			help: Some("ensure the number of values matches the column count".to_string()),
61			column: None,
62			notes: vec![],
63			cause: None,
64			operator_chain: None,
65		})
66	}
67
68	/// Error when the namespace is not found.
69	pub fn namespace_not_found(fragment: Fragment, namespace: &str) -> reifydb_type::error::Error {
70		reifydb_type::error::Error(Diagnostic {
71			code: "BI_004".to_string(),
72			statement: None,
73			message: format!("namespace `{}` not found", namespace),
74			fragment,
75			label: Some("unknown namespace".to_string()),
76			help: Some("create the namespace first or check the name".to_string()),
77			column: None,
78			notes: vec![],
79			cause: None,
80			operator_chain: None,
81		})
82	}
83
84	/// Error when the table is not found.
85	pub fn table_not_found(fragment: Fragment, namespace: &str, table: &str) -> reifydb_type::error::Error {
86		reifydb_type::error::Error(Diagnostic {
87			code: "BI_005".to_string(),
88			statement: None,
89			message: format!("table `{}.{}` not found", namespace, table),
90			fragment,
91			label: Some("unknown table".to_string()),
92			help: Some("create the table first or check the name".to_string()),
93			column: None,
94			notes: vec![],
95			cause: None,
96			operator_chain: None,
97		})
98	}
99
100	/// Error when the ring buffer is not found.
101	pub fn ringbuffer_not_found(
102		fragment: Fragment,
103		namespace: &str,
104		ringbuffer: &str,
105	) -> reifydb_type::error::Error {
106		reifydb_type::error::Error(Diagnostic {
107			code: "BI_006".to_string(),
108			statement: None,
109			message: format!("ring buffer `{}.{}` not found", namespace, ringbuffer),
110			fragment,
111			label: Some("unknown ring buffer".to_string()),
112			help: Some("create the ring buffer first or check the name".to_string()),
113			column: None,
114			notes: vec![],
115			cause: None,
116			operator_chain: None,
117		})
118	}
119}