1use spacedb_access::DenyReason;
7use thiserror::Error;
8
9use crate::schema::CrdtType;
10
11pub type SdkResult<T> = Result<T, SdkError>;
12
13#[derive(Debug, Error)]
14pub enum SdkError {
15 #[error("access denied: {0:?}")]
17 Denied(DenyReason),
18
19 #[error("over budget: op costs {cost} micro-$MATA, {remaining} remaining")]
21 OverBudget { cost: u64, remaining: u64 },
22
23 #[error("field '{field}' is a {found}, not a {expected}")]
25 WrongType {
26 field: String,
27 expected: CrdtType,
28 found: CrdtType,
29 },
30
31 #[error("field '{0}' is strong-tier; use claim_unique")]
33 StrongFieldNeedsClaim(String),
34
35 #[error("unknown collection '{0}'")]
37 UnknownCollection(String),
38
39 #[error("unknown field '{field}' in collection '{collection}'")]
41 UnknownField { collection: String, field: String },
42
43 #[error("crdt error: {0}")]
45 Crdt(String),
46
47 #[error("auth error: {0}")]
49 Auth(String),
50}
51
52impl std::fmt::Display for CrdtType {
53 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54 f.write_str(self.name())
55 }
56}