-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy patherror.rs
More file actions
169 lines (157 loc) · 6.24 KB
/
Copy patherror.rs
File metadata and controls
169 lines (157 loc) · 6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
use super::system_tables::SystemTable;
use spacetimedb_lib::db::raw_def::{v9::RawSql, RawIndexDefV8};
use spacetimedb_primitives::{ColId, ColList, IndexId, SequenceId, TableId, ViewId};
use spacetimedb_sats::buffer::DecodeError;
use spacetimedb_sats::product_value::InvalidFieldError;
use spacetimedb_sats::raw_identifier::RawIdentifier;
use spacetimedb_sats::{AlgebraicType, AlgebraicValue};
use spacetimedb_schema::def::error::LibError;
use spacetimedb_snapshot::SnapshotError;
use spacetimedb_table::{
bflatn_to, read_column,
table::{self, ReadViaBsatnError, UniqueConstraintViolation},
};
use thiserror::Error;
#[derive(Error, Debug)]
pub enum DatastoreError {
#[error("LibError: {0}")]
Lib(#[from] LibError),
#[error("TableError: {0}")]
Table(#[from] TableError),
#[error("IndexError: {0}")]
Index(#[from] IndexError),
#[error("SequenceError: {0}")]
Sequence(#[from] SequenceError),
#[error(transparent)]
// Box the inner [`SnapshotError`] to keep Clippy quiet about large `Err` variants.
Snapshot(#[from] Box<SnapshotError>),
// TODO(cloutiertyler): should this be a TableError? I couldn't get it to compile
#[error("Error reading a value from a table through BSATN: {0}")]
ReadViaBsatnError(#[from] ReadViaBsatnError),
#[error("ViewError: {0}")]
View(#[from] ViewError),
#[error(transparent)]
Other(#[from] anyhow::Error),
}
#[derive(Error, Debug)]
pub enum ViewError {
#[error("view '{0}' not found")]
NotFound(RawIdentifier),
#[error("Table backing View '{0}' not found")]
TableNotFound(ViewId),
#[error("failed to deserialize view arguments from row")]
DeserializeArgs,
#[error("failed to deserialize view return value: {0}")]
DeserializeReturn(String),
#[error("failed to serialize row to BSATN")]
SerializeRow,
#[error("invalid return type: expected Array or Option, got {0:?}")]
InvalidReturnType(AlgebraicType),
#[error("return type is Array but deserialized value is not Array")]
TypeMismatchArray,
#[error("return type is Option but deserialized value is not Option")]
TypeMismatchOption,
#[error("expected ProductValue in view result")]
ExpectedProduct,
}
#[derive(Error, Debug)]
pub enum TableError {
#[error("Table with name `{0}` not found.")]
NotFound(String),
#[error("Table with ID `{1}` not found in `{0}`.")]
IdNotFound(SystemTable, u32),
#[error("Sql `{1}` not found in `{0}`.")]
RawSqlNotFound(SystemTable, RawSql),
#[error("Table with ID `{0}` not found in `TxState`.")]
IdNotFoundState(TableId),
#[error("Column `{0}` not found")]
ColumnNotFound(ColId),
#[error(transparent)]
Bflatn(#[from] bflatn_to::Error),
#[error(transparent)]
Duplicate(#[from] table::DuplicateError),
#[error(transparent)]
ReadColTypeError(#[from] read_column::TypeError),
#[error(transparent)]
// Error here is `Box`ed to avoid triggering https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err .
ChangeColumnsError(#[from] Box<table::ChangeColumnsError>),
#[error(transparent)]
AddColumnsError(#[from] Box<table::AddColumnsError>),
#[error("Event table with ID `{0}` is not empty")]
EventTableNotEmpty(TableId),
#[error(
"Table with ID `{0}` attempted to reschema using `alter_event_table_row_type`, but it is not an event table"
)]
ReschemaNotAnEventTable(TableId),
}
#[derive(Error, Debug, PartialEq, Eq)]
pub enum IndexError {
#[error("Index not found: {0:?}")]
NotFound(IndexId),
#[error("Column not found: {0:?}")]
ColumnNotFound(RawIndexDefV8),
#[error(transparent)]
UniqueConstraintViolation(#[from] UniqueConstraintViolation),
#[error("Attempt to define a index with more than 1 auto_inc column: Table: {0:?}, Columns: {1:?}")]
OneAutoInc(TableId, Vec<String>),
#[error("Could not decode arguments to index scan")]
Decode(DecodeError),
#[error("Index was not unique: {0:?}")]
NotUnique(IndexId),
#[error("Key {1:?} was not found in index {0:?}")]
KeyNotFound(IndexId, AlgebraicValue),
#[error("IndexId {0:?} does not support seeking for a range")]
IndexCannotSeekRange(IndexId),
}
#[derive(Error, Debug, PartialEq, Eq)]
pub enum SequenceError {
#[error("Sequence with name `{0}` already exists.")]
Exist(String),
#[error("Sequence `{0}`: The increment is 0, and this means the sequence can't advance.")]
IncrementIsZero(String),
#[error("Sequence `{0}`: The min_value {1} must < max_value {2}.")]
MinMax(String, i128, i128),
#[error("Sequence `{0}`: The start value {1} must be >= min_value {2}.")]
MinStart(String, i128, i128),
#[error("Sequence `{0}`: The start value {1} must be <= min_value {2}.")]
MaxStart(String, i128, i128),
#[error("Sequence `{0}` failed to decode value from Sled (not a u128).")]
SequenceValue(String),
#[error("Sequence ID `{0}` not found.")]
NotFound(SequenceId),
#[error("Sequence applied to a non-integer field. Column `{col}` is of type {{found.to_sats()}}.")]
NotInteger { col: String, found: AlgebraicType },
#[error("Sequence ID `{0}` still had no values left after allocation.")]
UnableToAllocate(SequenceId),
#[error("Autoinc constraint on table {0:?} spans more than one column: {1:?}")]
MultiColumnAutoInc(TableId, ColList),
}
impl From<InvalidFieldError> for DatastoreError {
fn from(value: InvalidFieldError) -> Self {
LibError::from(value).into()
}
}
impl From<spacetimedb_table::read_column::TypeError> for DatastoreError {
fn from(err: spacetimedb_table::read_column::TypeError) -> Self {
TableError::from(err).into()
}
}
impl From<table::InsertError> for DatastoreError {
fn from(err: table::InsertError) -> Self {
match err {
table::InsertError::Duplicate(e) => TableError::from(e).into(),
table::InsertError::Bflatn(e) => TableError::from(e).into(),
table::InsertError::IndexError(e) => IndexError::from(e).into(),
}
}
}
impl From<bflatn_to::Error> for DatastoreError {
fn from(err: bflatn_to::Error) -> Self {
Self::Table(err.into())
}
}
impl From<SnapshotError> for DatastoreError {
fn from(e: SnapshotError) -> Self {
DatastoreError::Snapshot(Box::new(e))
}
}