1//! Errors that can occur when inserting into a [`Tree`], deserializing [`Proof`](super::Proof)s, or
2//! checking internal invariants.
34use crate::builder;
5#[cfg(doc)]
6use crate::prelude::*;
78#[doc(inline)]
9pub use crate::tree::RootDecodeError;
1011pub mod proof {
12//! Errors from deserializing or verifying inclusion proofs.
13#[doc(inline)]
14pub use crate::internal::{
15 path::PathDecodeError,
16 proof::{ProofDecodeError as DecodeError, VerifyError},
17 };
18}
1920pub mod block {
21//! Errors for [`block`](self) builders.
2223 /// An error occurred when decoding a [`block::Root`](crate::builder::block::Root) from bytes.
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
25 #[error("could not decode block root")]
26pub struct RootDecodeError;
2728/// When inserting into a [`block::Builder`](crate::builder::block::Builder), this error is
29 /// returned when it is full.
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
31 #[error("block is full")]
32 #[non_exhaustive]
33pub struct InsertError;
34}
3536pub mod epoch {
37//! Errors for [`epoch`] builders.
38use super::*;
3940/// An error occurred when decoding an [`epoch::Root`](builder::epoch::Root) from bytes.
41#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
42 #[error("could not decode epoch root")]
43pub struct RootDecodeError;
4445/// A [`Commitment`] could not be inserted into the [`epoch::Builder`](builder::epoch::Builder).
46#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
47pub enum InsertError {
48/// The [`epoch::Builder`](builder::epoch::Builder) was full.
49#[error("epoch is full")]
50 #[non_exhaustive]
51Full,
52/// The most recent block in the [`epoch::Builder`](builder::epoch::Builder) was full.
53#[error("most recent block in epoch is full")]
54 #[non_exhaustive]
55BlockFull,
56 }
5758/// The [`epoch::Builder`](builder::epoch::Builder) was full when attempting to insert a block.
59#[derive(Debug, Clone, Error)]
60 #[error("epoch is full")]
61 #[non_exhaustive]
62pub struct InsertBlockError(pub builder::block::Finalized);
63}
6465/// An error occurred when trying to insert a [`Commitment`] into a [`Tree`].
66#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
67pub enum InsertError {
68/// The [`Tree`] was full.
69#[error("tree is full")]
70Full,
71/// The most recent epoch of the [`Tree`] was full.
72#[error("most recent epoch in tree is full")]
73EpochFull,
74/// The most recent block of the most recent epoch of the [`Tree`] was full.
75#[error("most recent block in most recent epoch of tree is full")]
76BlockFull,
77}
7879/// An error occurred when trying to insert a block into the [`Tree`].
80#[derive(Debug, Clone, Error)]
81pub enum InsertBlockError {
82/// The [`Tree`] was full.
83#[error("tree is full")]
84 #[non_exhaustive]
85Full(builder::block::Finalized),
86/// The most recent epoch of the [`Tree`] was full.
87#[error("most recent epoch is full")]
88 #[non_exhaustive]
89EpochFull(builder::block::Finalized),
90}
9192impl From<InsertBlockError> for builder::block::Finalized {
93fn from(error: InsertBlockError) -> Self {
94match error {
95 InsertBlockError::Full(block) => block,
96 InsertBlockError::EpochFull(block) => block,
97 }
98 }
99}
100101/// The [`Tree`] was full when trying to insert an epoch into it.
102#[derive(Debug, Clone, Error)]
103#[error("tree is full")]
104#[non_exhaustive]
105pub struct InsertEpochError(pub builder::epoch::Finalized);
106107impl From<InsertEpochError> for builder::epoch::Finalized {
108fn from(error: InsertEpochError) -> Self {
109 error.0
110}
111}
112113#[cfg(test)]
114mod test {
115use super::*;
116117#[test]
118fn insert_errors_sync_send() {
119static_assertions::assert_impl_all!(InsertError: Sync, Send);
120static_assertions::assert_impl_all!(InsertBlockError: Sync, Send);
121static_assertions::assert_impl_all!(InsertEpochError: Sync, Send);
122 }
123}