icydb_core/db/schema/
errors.rs1use crate::{
7 db::{
8 identity::{EntityNameError, IndexNameError},
9 predicate::{CoercionId, UnsupportedQueryFeature},
10 },
11 model::index::{IndexExpression, IndexModel},
12};
13use std::fmt;
14
15#[derive(Debug, thiserror::Error)]
17pub enum ValidateError {
18 #[error("invalid entity name '{name}': {source}")]
19 InvalidEntityName {
20 name: String,
21 #[source]
22 source: EntityNameError,
23 },
24
25 #[error("invalid index name for '{index}': {source}")]
26 InvalidIndexName {
27 index: IndexModel,
28 #[source]
29 source: IndexNameError,
30 },
31
32 #[error("unknown field '{field}'")]
33 UnknownField { field: String },
34
35 #[error("field '{field}' is not queryable")]
36 NonQueryableFieldType { field: String },
37
38 #[error("duplicate field '{field}'")]
39 DuplicateField { field: String },
40
41 #[error("{0}")]
42 UnsupportedQueryFeature(#[from] UnsupportedQueryFeature),
43
44 #[error("primary key '{field}' not present in entity fields")]
45 InvalidPrimaryKey { field: String },
46
47 #[error("primary key '{field}' has a non-keyable type")]
48 InvalidPrimaryKeyType { field: String },
49
50 #[error("index '{index}' references unknown field '{field}'")]
51 IndexFieldUnknown { index: IndexModel, field: String },
52
53 #[error("index '{index}' references non-queryable field '{field}'")]
54 IndexFieldNotQueryable { index: IndexModel, field: String },
55
56 #[error(
57 "index '{index}' references map field '{field}'; map fields are not queryable in icydb 0.7"
58 )]
59 IndexFieldMapNotQueryable { index: IndexModel, field: String },
60
61 #[error("index '{index}' repeats field '{field}'")]
62 IndexFieldDuplicate { index: IndexModel, field: String },
63
64 #[error("index '{index}' expression key item '{expression}' requires {expected}")]
65 IndexExpressionFieldTypeInvalid {
66 index: &'static str,
67 expression: IndexExpression,
68 expected: &'static str,
69 },
70
71 #[error("duplicate index name '{name}'")]
72 DuplicateIndexName { name: String },
73
74 #[error("index '{index}' predicate '{predicate}' has invalid SQL syntax")]
75 InvalidIndexPredicateSyntax {
76 index: IndexModel,
77 predicate: &'static str,
78 },
79
80 #[error("index '{index}' predicate '{predicate}' is invalid for schema")]
81 InvalidIndexPredicateSchema {
82 index: IndexModel,
83 predicate: &'static str,
84 },
85
86 #[error("operator {op} is not valid for field '{field}'")]
87 InvalidOperator { field: String, op: String },
88
89 #[error("coercion {coercion:?} is not valid for field '{field}'")]
90 InvalidCoercion { field: String, coercion: CoercionId },
91
92 #[error("invalid literal for field '{field}': {message}")]
93 InvalidLiteral { field: String, message: String },
94}
95
96impl ValidateError {
97 pub(crate) fn invalid_operator(field: &str, op: impl fmt::Display) -> Self {
98 Self::InvalidOperator {
99 field: field.to_string(),
100 op: op.to_string(),
101 }
102 }
103
104 pub(crate) fn invalid_literal(field: &str, msg: &str) -> Self {
105 Self::InvalidLiteral {
106 field: field.to_string(),
107 message: msg.to_string(),
108 }
109 }
110
111 pub(crate) const fn invalid_index_predicate_syntax(
112 index: IndexModel,
113 predicate: &'static str,
114 ) -> Self {
115 Self::InvalidIndexPredicateSyntax { index, predicate }
116 }
117
118 pub(crate) const fn invalid_index_predicate_schema(
119 index: IndexModel,
120 predicate: &'static str,
121 ) -> Self {
122 Self::InvalidIndexPredicateSchema { index, predicate }
123 }
124
125 pub(crate) const fn invalid_index_expression_field_type(
126 index: IndexModel,
127 expression: IndexExpression,
128 expected: &'static str,
129 ) -> Self {
130 Self::IndexExpressionFieldTypeInvalid {
131 index: index.name(),
132 expression,
133 expected,
134 }
135 }
136}