workflow_egui/
error.rs

1use thiserror::Error;
2use workflow_core::channel::{RecvError, SendError, TrySendError};
3
4pub type DynError = Box<dyn std::error::Error + Send + Sync>;
5
6#[derive(Error, Debug)]
7pub enum Error {
8    #[error("{0}")]
9    Custom(String),
10
11    #[error("{0}")]
12    Eframe(String),
13
14    #[error(transparent)]
15    DynError(#[from] DynError),
16
17    #[error("Channel send() error")]
18    SendError,
19
20    #[error("Channel try_send() error")]
21    TrySendError,
22
23    #[error("Channel recv() error")]
24    RecvError,
25}
26
27impl Error {
28    pub fn custom<T: Into<String>>(msg: T) -> Self {
29        Error::Custom(msg.into())
30    }
31}
32
33impl From<&str> for Error {
34    fn from(err: &str) -> Self {
35        Error::Custom(err.to_string())
36    }
37}
38
39impl From<String> for Error {
40    fn from(err: String) -> Self {
41        Error::Custom(err)
42    }
43}
44
45impl From<eframe::Error> for Error {
46    fn from(err: eframe::Error) -> Self {
47        Error::Eframe(err.to_string())
48    }
49}
50
51// impl From<std::io::Error> for Error {
52//     fn from(err: std::io::Error) -> Self {
53//         Error::Io(err)
54//     }
55// }
56
57impl<T> From<SendError<T>> for Error {
58    fn from(_: SendError<T>) -> Self {
59        Error::SendError
60    }
61}
62
63impl From<RecvError> for Error {
64    fn from(_: RecvError) -> Self {
65        Error::RecvError
66    }
67}
68
69impl<T> From<TrySendError<T>> for Error {
70    fn from(_: TrySendError<T>) -> Self {
71        Error::TrySendError
72    }
73}