Skip to main content

reifydb_sub_column/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use reifydb_core::interface::catalog::id::{NamespaceId, SeriesId};
5use reifydb_type::{
6	error::{Diagnostic, Error, IntoDiagnostic},
7	fragment::Fragment,
8};
9
10#[derive(Debug, thiserror::Error)]
11pub enum SubColumnError {
12	#[error("column_block_from_batches: scan output missing column '{column}'")]
13	MissingColumnInBatch {
14		column: String,
15	},
16
17	#[error("column_block_from_batches: no batches to materialize column '{column}'")]
18	NoBatchesForMaterialization {
19		column: String,
20	},
21
22	#[error("series materialization: namespace {namespace:?} missing for series {series:?}")]
23	NamespaceMissing {
24		namespace: NamespaceId,
25		series: SeriesId,
26	},
27}
28
29impl From<SubColumnError> for Error {
30	fn from(err: SubColumnError) -> Self {
31		Error(Box::new(err.into_diagnostic()))
32	}
33}
34
35impl IntoDiagnostic for SubColumnError {
36	fn into_diagnostic(self) -> Diagnostic {
37		match self {
38			SubColumnError::MissingColumnInBatch {
39				column,
40			} => Diagnostic {
41				code: "SCOL_001".to_string(),
42				rql: None,
43				message: format!("column_block_from_batches: scan output missing column '{column}'"),
44				column: None,
45				fragment: Fragment::None,
46				label: Some("column missing in scan batch".to_string()),
47				help: Some("the scan output schema must include every column named in the target schema".to_string()),
48				notes: vec![],
49				cause: None,
50				operator_chain: None,
51			},
52
53			SubColumnError::NoBatchesForMaterialization {
54				column,
55			} => Diagnostic {
56				code: "SCOL_002".to_string(),
57				rql: None,
58				message: format!("column_block_from_batches: no batches to materialize column '{column}'"),
59				column: None,
60				fragment: Fragment::None,
61				label: None,
62				help: None,
63				notes: vec![],
64				cause: None,
65				operator_chain: None,
66			},
67
68			SubColumnError::NamespaceMissing {
69				namespace,
70				series,
71			} => Diagnostic {
72				code: "SCOL_003".to_string(),
73				rql: None,
74				message: format!("series materialization: namespace {namespace:?} missing for series {series:?}"),
75				column: None,
76				fragment: Fragment::None,
77				label: Some("namespace not found in catalog".to_string()),
78				help: Some("the series references a namespace that is no longer present; catalog may be out of sync".to_string()),
79				notes: vec![],
80				cause: None,
81				operator_chain: None,
82			},
83		}
84	}
85}