icydb_core/db/schema/
errors.rs1use crate::{
7 db::{
8 identity::{EntityNameError, IndexNameError},
9 predicate::{CoercionId, UnsupportedQueryFeature},
10 },
11 model::index::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(
65 "index '{index}' declares unsupported expression key item '{expression}' in this release"
66 )]
67 IndexExpressionUnsupported {
68 index: IndexModel,
69 expression: &'static str,
70 },
71
72 #[error("duplicate index name '{name}'")]
73 DuplicateIndexName { name: String },
74
75 #[error("index '{index}' predicate '{predicate}' has invalid SQL syntax")]
76 InvalidIndexPredicateSyntax {
77 index: IndexModel,
78 predicate: &'static str,
79 },
80
81 #[error("index '{index}' predicate '{predicate}' is invalid for schema")]
82 InvalidIndexPredicateSchema {
83 index: IndexModel,
84 predicate: &'static str,
85 },
86
87 #[error("operator {op} is not valid for field '{field}'")]
88 InvalidOperator { field: String, op: String },
89
90 #[error("coercion {coercion:?} is not valid for field '{field}'")]
91 InvalidCoercion { field: String, coercion: CoercionId },
92
93 #[error("invalid literal for field '{field}': {message}")]
94 InvalidLiteral { field: String, message: String },
95}
96
97impl ValidateError {
98 pub(crate) fn invalid_operator(field: &str, op: impl fmt::Display) -> Self {
99 Self::InvalidOperator {
100 field: field.to_string(),
101 op: op.to_string(),
102 }
103 }
104
105 pub(crate) fn invalid_literal(field: &str, msg: &str) -> Self {
106 Self::InvalidLiteral {
107 field: field.to_string(),
108 message: msg.to_string(),
109 }
110 }
111
112 pub(crate) const fn invalid_index_predicate_syntax(
113 index: IndexModel,
114 predicate: &'static str,
115 ) -> Self {
116 Self::InvalidIndexPredicateSyntax { index, predicate }
117 }
118
119 pub(crate) const fn invalid_index_predicate_schema(
120 index: IndexModel,
121 predicate: &'static str,
122 ) -> Self {
123 Self::InvalidIndexPredicateSchema { index, predicate }
124 }
125
126 pub(crate) const fn index_expression_unsupported(
127 index: IndexModel,
128 expression: &'static str,
129 ) -> Self {
130 Self::IndexExpressionUnsupported { index, expression }
131 }
132}