1use bytes::Bytes;
2
3use crate::codecs::CodecError;
4
5#[derive(Debug)]
6pub enum Error {
7 ConfusedFrame,
8 IncompleteErrorFrame,
9 UnmatchedReply,
10 RecvError,
11 SendError,
12 Codec(CodecError),
13 Serde(amp_serde::Error),
14 Remote { code: Bytes, description: Bytes },
15 IO(std::io::Error),
16}
17
18impl std::fmt::Display for Error {
19 fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
20 write!(fmt, "{:?}", self)
21 }
22}
23
24impl std::error::Error for Error {}
25
26impl From<CodecError> for Error {
27 fn from(error: CodecError) -> Self {
28 Self::Codec(error)
29 }
30}
31
32impl From<tokio::sync::oneshot::error::RecvError> for Error {
33 fn from(_error: tokio::sync::oneshot::error::RecvError) -> Self {
34 Self::RecvError
35 }
36}
37
38impl<T> From<tokio::sync::mpsc::error::SendError<T>> for Error {
39 fn from(_error: tokio::sync::mpsc::error::SendError<T>) -> Self {
40 Self::SendError
41 }
42}
43
44impl From<std::io::Error> for Error {
45 fn from(error: std::io::Error) -> Self {
46 Self::IO(error)
47 }
48}
49
50impl From<amp_serde::Error> for Error {
51 fn from(error: amp_serde::Error) -> Self {
52 Self::Serde(error)
53 }
54}