p2panda_rs/schema/
error.rs1use thiserror::Error;
5
6use crate::schema::SchemaId;
7
8#[derive(Clone, Error, Debug)]
10pub enum SchemaNameError {
11 #[error("Schema name contains too many or invalid characters")]
13 MalformedSchemaName,
14}
15
16impl Copy for SchemaNameError {}
17
18#[derive(Clone, Error, Debug)]
20pub enum SchemaDescriptionError {
21 #[error("Schema description contains more than 256 characters")]
23 TooLongSchemaDescription,
24}
25
26#[derive(Clone, Error, Debug)]
28pub enum SchemaFieldError {
29 #[error("Schema field found with invalid name")]
31 MalformedSchemaFieldName,
32
33 #[error("Schema fields contains more than 1024 fields")]
35 TooManyFields,
36
37 #[error("Schema fields must contain at least one entry")]
39 ZeroFields,
40
41 #[error("Schema fields cannot contain duplicate field names")]
43 DuplicateFields,
44}
45
46#[derive(Error, Debug)]
48pub enum SchemaIdError {
49 #[error("malformed schema id `{0}`: {1}")]
51 MalformedSchemaId(String, String),
52
53 #[error("application schema id is missing a name: {0}")]
55 MissingApplicationSchemaName(String),
56
57 #[error("unsupported system schema: {0}")]
59 UnknownSystemSchema(String),
60
61 #[error("encountered invalid hash while parsing application schema id: {0}")]
63 HashError(#[from] crate::hash::error::HashError),
64
65 #[error("encountered invalid document view id while parsing application schema id: {0}")]
67 DocumentViewIdError(#[from] crate::document::error::DocumentViewIdError),
68
69 #[error("encountered invalid hash while parsing application schema id: {0}")]
71 OperationIdError(#[from] crate::operation::error::OperationIdError),
72}
73
74#[derive(Error, Debug)]
76pub enum SchemaError {
77 #[error("invalid fields found for this schema")]
79 InvalidFields,
80
81 #[error("dynamic redefinition of system schema {0}, use `Schema::get_system` instead")]
83 DynamicSystemSchema(SchemaId),
84
85 #[error(transparent)]
87 SchemaIdError(#[from] SchemaIdError),
88
89 #[error(transparent)]
91 SchemaNameError(#[from] SchemaNameError),
92
93 #[error(transparent)]
95 SchemaDescriptionError(#[from] SchemaDescriptionError),
96
97 #[error(transparent)]
99 SchemaFieldsError(#[from] SchemaFieldError),
100}
101
102#[derive(Error, Debug)]
104pub enum FieldTypeError {
105 #[error("invalid field type '{0}'")]
107 InvalidFieldType(String),
108
109 #[error(transparent)]
111 RelationSchemaReference(#[from] SchemaIdError),
112}