1use ckb_channel::oneshot::RecvError;
4use ckb_error::{
5 Error, InternalError, InternalErrorKind, OtherError, impl_error_conversion_with_adaptor,
6 impl_error_conversion_with_kind, prelude::*,
7};
8pub use ckb_types::core::tx_pool::Reject;
9use std::fmt;
10use tokio::sync::mpsc::error::TrySendError;
11use tokio::sync::watch::error::SendError;
12
13#[derive(Error, Debug, PartialEq, Clone, Eq)]
15pub enum BlockAssemblerError {
16 #[error("InvalidInput")]
18 InvalidInput,
19 #[error("InvalidParams {0}")]
21 InvalidParams(String),
22 #[error("Disabled")]
24 Disabled,
25 #[error("Overflow")]
27 Overflow,
28}
29
30impl_error_conversion_with_kind!(
31 BlockAssemblerError,
32 InternalErrorKind::BlockAssembler,
33 InternalError
34);
35
36impl_error_conversion_with_adaptor!(BlockAssemblerError, InternalError, Error);
37
38pub(crate) fn handle_try_send_error<T>(error: TrySendError<T>) -> (T, OtherError) {
39 let e = OtherError::new(format!("TrySendError {error}"));
40 let m = match error {
41 TrySendError::Full(t) | TrySendError::Closed(t) => t,
42 };
43 (m, e)
44}
45
46pub(crate) fn handle_recv_error(error: RecvError) -> OtherError {
47 OtherError::new(format!("RecvError {error}"))
48}
49
50pub(crate) fn handle_send_cmd_error<T: fmt::Debug>(error: SendError<T>) -> OtherError {
51 OtherError::new(format!("send command fails: {error:?}"))
52}