Skip to main content

tightbeam/builder/
error.rs

1#[cfg(not(feature = "std"))]
2extern crate alloc;
3
4use crate::{Errorizable, Version};
5
6/// Errors specific to metadata validation
7#[derive(Errorizable, Debug, Clone, PartialEq, Eq)]
8pub enum MetadataError {
9	/// Missing required ID field
10	#[error("Missing required field: id")]
11	MissingId,
12
13	/// Missing required order field
14	#[error("Missing required field: order")]
15	MissingTimestamp,
16
17	/// Missing required hash field (V2+)
18	#[error("Missing required field: hash (required for V2)")]
19	MissingHash,
20
21	/// Missing required encryption info (V1+)
22	#[error("Missing required field: encryption (required for V1+)")]
23	MissingEncryption,
24
25	/// Field not supported in this protocol version
26	#[error("Field '{field}' is not supported in protocol version {version:?}")]
27	UnsupportedField { field: &'static str, version: Version },
28}
29
30/// Errors that can occur during builder operations
31#[derive(Errorizable, Debug)]
32pub enum BuildError {
33	/// Invalid metadata configuration
34	#[error("Invalid metadata: {0}")]
35	#[from]
36	#[source]
37	InvalidMetadata(MetadataError),
38
39	/// Invalid matrix dimensions or contents
40	#[error("Matrix error: {0}")]
41	#[from]
42	#[source]
43	MatrixError(crate::matrix::MatrixError),
44
45	/// Error during serialization
46	#[error("Serialization error: {0}")]
47	#[from]
48	#[source]
49	Serialization(der::Error),
50
51	/// Error during encryption
52	#[cfg(feature = "aead")]
53	#[error("Encryption error: {0}")]
54	#[from]
55	#[source]
56	Encryption(aead::Error),
57
58	/// Error during signing
59	#[cfg(feature = "signature")]
60	#[error("Signature error: {0}")]
61	#[from]
62	#[source]
63	Signature(signature::Error),
64
65	/// Error during compression
66	#[cfg(feature = "compress")]
67	#[error("Compression error: {0}")]
68	Compression(crate::error::CompressionError),
69
70	/// Error obtaining random bytes
71	#[cfg(feature = "random")]
72	#[error("Random number generation error: {0}")]
73	#[from]
74	#[source]
75	Random(rand_core::Error),
76
77	/// Missing message body
78	#[error("Missing message body")]
79	MissingMessage,
80}