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("duplicate index name '{name}'")]
65 DuplicateIndexName { name: String },
66
67 #[error("index '{index}' predicate '{predicate}' has invalid SQL syntax")]
68 InvalidIndexPredicateSyntax {
69 index: IndexModel,
70 predicate: &'static str,
71 },
72
73 #[error("index '{index}' predicate '{predicate}' is invalid for schema")]
74 InvalidIndexPredicateSchema {
75 index: IndexModel,
76 predicate: &'static str,
77 },
78
79 #[error("operator {op} is not valid for field '{field}'")]
80 InvalidOperator { field: String, op: String },
81
82 #[error("coercion {coercion:?} is not valid for field '{field}'")]
83 InvalidCoercion { field: String, coercion: CoercionId },
84
85 #[error("invalid literal for field '{field}': {message}")]
86 InvalidLiteral { field: String, message: String },
87}
88
89impl ValidateError {
90 pub(crate) fn invalid_operator(field: &str, op: impl fmt::Display) -> Self {
91 Self::InvalidOperator {
92 field: field.to_string(),
93 op: op.to_string(),
94 }
95 }
96
97 pub(crate) fn invalid_literal(field: &str, msg: &str) -> Self {
98 Self::InvalidLiteral {
99 field: field.to_string(),
100 message: msg.to_string(),
101 }
102 }
103
104 pub(crate) const fn invalid_index_predicate_syntax(
105 index: IndexModel,
106 predicate: &'static str,
107 ) -> Self {
108 Self::InvalidIndexPredicateSyntax { index, predicate }
109 }
110
111 pub(crate) const fn invalid_index_predicate_schema(
112 index: IndexModel,
113 predicate: &'static str,
114 ) -> Self {
115 Self::InvalidIndexPredicateSchema { index, predicate }
116 }
117}