kona_preimage/
errors.rs

1//! Errors for the `kona-preimage` crate.
2
3use alloc::string::String;
4use thiserror::Error;
5
6/// A [PreimageOracleError] is an enum that differentiates pipe-related errors from other errors
7/// in the [PreimageOracleServer] and [HintReaderServer] implementations.
8///
9/// [PreimageOracleServer]: crate::PreimageOracleServer
10/// [HintReaderServer]: crate::HintReaderServer
11#[derive(Error, Debug)]
12pub enum PreimageOracleError {
13    /// The pipe has been broken.
14    #[error(transparent)]
15    IOError(#[from] ChannelError),
16    /// The preimage key is invalid.
17    #[error("Invalid preimage key.")]
18    InvalidPreimageKey,
19    /// Key not found.
20    #[error("Key not found.")]
21    KeyNotFound,
22    /// Buffer length mismatch.
23    #[error("Buffer length mismatch. Expected {0}, got {1}.")]
24    BufferLengthMismatch(usize, usize),
25    /// Other errors.
26    #[error("Error in preimage server: {0}")]
27    Other(String),
28}
29
30/// A [Result] type for the [PreimageOracleError] enum.
31pub type PreimageOracleResult<T> = Result<T, PreimageOracleError>;
32
33/// A [ChannelError] is an enum that describes the error cases of a [Channel] trait implementation.
34///
35/// [Channel]: crate::Channel
36#[derive(Error, Debug)]
37pub enum ChannelError {
38    /// The channel is closed.
39    #[error("Channel is closed.")]
40    Closed,
41    /// Unexpected EOF.
42    #[error("Unexpected EOF in channel read operation.")]
43    UnexpectedEOF,
44}
45
46/// A [Result] type for the [ChannelError] enum.
47pub type ChannelResult<T> = Result<T, ChannelError>;