reifydb_engine/bulk_insert/
error.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later, see license.md file
3
4//! Error types for bulk insert operations.
5
6use reifydb_type::{Fragment, diagnostic::Diagnostic};
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 {
14		reifydb_type::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		})
25	}
26
27	/// Error when there's a type mismatch between the value and column.
28	pub fn type_mismatch(fragment: Fragment, column: &str, expected: &str, actual: &str) -> reifydb_type::Error {
29		reifydb_type::Error(Diagnostic {
30			code: "BI_002".to_string(),
31			statement: None,
32			message: format!(
33				"type mismatch for column `{}`: expected `{}`, got `{}`",
34				column, expected, actual
35			),
36			fragment,
37			label: Some("incompatible type".to_string()),
38			help: Some("ensure the value type matches the column definition".to_string()),
39			column: None,
40			notes: vec![],
41			cause: None,
42		})
43	}
44
45	/// Error when more values are provided than columns exist.
46	pub fn too_many_values(fragment: Fragment, expected: usize, actual: usize) -> reifydb_type::Error {
47		reifydb_type::Error(Diagnostic {
48			code: "BI_003".to_string(),
49			statement: None,
50			message: format!("too many values: expected {} columns, got {}", expected, actual),
51			fragment,
52			label: Some("value count mismatch".to_string()),
53			help: Some("ensure the number of values matches the column count".to_string()),
54			column: None,
55			notes: vec![],
56			cause: None,
57		})
58	}
59
60	/// Error when the namespace is not found.
61	pub fn namespace_not_found(fragment: Fragment, namespace: &str) -> reifydb_type::Error {
62		reifydb_type::Error(Diagnostic {
63			code: "BI_004".to_string(),
64			statement: None,
65			message: format!("namespace `{}` not found", namespace),
66			fragment,
67			label: Some("unknown namespace".to_string()),
68			help: Some("create the namespace first or check the name".to_string()),
69			column: None,
70			notes: vec![],
71			cause: None,
72		})
73	}
74
75	/// Error when the table is not found.
76	pub fn table_not_found(fragment: Fragment, namespace: &str, table: &str) -> reifydb_type::Error {
77		reifydb_type::Error(Diagnostic {
78			code: "BI_005".to_string(),
79			statement: None,
80			message: format!("table `{}.{}` not found", namespace, table),
81			fragment,
82			label: Some("unknown table".to_string()),
83			help: Some("create the table first or check the name".to_string()),
84			column: None,
85			notes: vec![],
86			cause: None,
87		})
88	}
89
90	/// Error when the ring buffer is not found.
91	pub fn ringbuffer_not_found(fragment: Fragment, namespace: &str, ringbuffer: &str) -> reifydb_type::Error {
92		reifydb_type::Error(Diagnostic {
93			code: "BI_006".to_string(),
94			statement: None,
95			message: format!("ring buffer `{}.{}` not found", namespace, ringbuffer),
96			fragment,
97			label: Some("unknown ring buffer".to_string()),
98			help: Some("create the ring buffer first or check the name".to_string()),
99			column: None,
100			notes: vec![],
101			cause: None,
102		})
103	}
104}