Skip to main content

workflow_egui/
error.rs

1use thiserror::Error;
2use workflow_core::channel::{RecvError, SendError, TrySendError};
3
4/// Boxed, thread-safe dynamic error type used for opaque error propagation.
5pub type DynError = Box<dyn std::error::Error + Send + Sync>;
6
7/// Errors produced by this crate.
8#[derive(Error, Debug)]
9pub enum Error {
10    /// A custom, free-form error message.
11    #[error("{0}")]
12    Custom(String),
13
14    /// An error originating from `eframe`, captured as a string.
15    #[error("{0}")]
16    Eframe(String),
17
18    /// A wrapped dynamic error from another source.
19    #[error(transparent)]
20    DynError(#[from] DynError),
21
22    /// A channel `send()` operation failed.
23    #[error("Channel send() error")]
24    SendError,
25
26    /// A channel `try_send()` operation failed.
27    #[error("Channel try_send() error")]
28    TrySendError,
29
30    /// A channel `recv()` operation failed.
31    #[error("Channel recv() error")]
32    RecvError,
33}
34
35impl Error {
36    /// Construct an [`Error::Custom`] from any value convertible into a `String`.
37    pub fn custom<T: Into<String>>(msg: T) -> Self {
38        Error::Custom(msg.into())
39    }
40}
41
42impl From<&str> for Error {
43    fn from(err: &str) -> Self {
44        Error::Custom(err.to_string())
45    }
46}
47
48impl From<String> for Error {
49    fn from(err: String) -> Self {
50        Error::Custom(err)
51    }
52}
53
54impl From<eframe::Error> for Error {
55    fn from(err: eframe::Error) -> Self {
56        Error::Eframe(err.to_string())
57    }
58}
59
60// impl From<std::io::Error> for Error {
61//     fn from(err: std::io::Error) -> Self {
62//         Error::Io(err)
63//     }
64// }
65
66impl<T> From<SendError<T>> for Error {
67    fn from(_: SendError<T>) -> Self {
68        Error::SendError
69    }
70}
71
72impl From<RecvError> for Error {
73    fn from(_: RecvError) -> Self {
74        Error::RecvError
75    }
76}
77
78impl<T> From<TrySendError<T>> for Error {
79    fn from(_: TrySendError<T>) -> Self {
80        Error::TrySendError
81    }
82}