use thiserror::Error;
use tokio::sync::oneshot::error::RecvError;
#[derive(Debug, Error)]
pub enum LinkError {
#[error("streamable error: {0}")]
Streamable(#[from] chia_traits::Error),
#[error("websocket error: {0}")]
WebSocket(Box<tungstenite::Error>),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("expected a response with opcode in {0:?}, found {1}")]
InvalidResponse(Vec<u8>, u8),
#[error("the link closed before a response arrived")]
Recv(#[from] RecvError),
#[error("the websocket's TLS backend is not supported by this build")]
UnsupportedTls,
#[error("a message with opcode {0} and a {1}-byte body exceeds the per-message limit")]
Unsendable(u8, usize),
#[error("timed out waiting for rate-limit budget to send opcode {0}")]
SendTimeout(u8),
#[error("timed out waiting for a response to opcode {0}")]
RequestTimeout(u8),
#[error("message type did not encode to a single-byte opcode")]
MalformedOpcode,
}
impl From<tungstenite::Error> for LinkError {
fn from(error: tungstenite::Error) -> Self {
Self::WebSocket(Box::new(error))
}
}