workflow_node/
error.rs

1//! Errors produced by the the [`node`](super) crate
2use thiserror::Error;
3use wasm_bindgen::prelude::*;
4use workflow_core::channel::{RecvError, SendError, TryRecvError};
5use workflow_wasm::printable::Printable;
6
7#[derive(Debug, Error)]
8pub enum Error {
9    #[error("Already running")]
10    AlreadyRunning,
11    #[error("The task is not running")]
12    NotRunning,
13    #[error("Child process reference is absent")]
14    ProcIsAbsent,
15    #[error("{0:?}")]
16    Send(String),
17    #[error("{0:?}")]
18    Recv(#[from] RecvError),
19    #[error("{0:?}")]
20    TryRecv(#[from] TryRecvError),
21    #[error(transparent)]
22    Task(#[from] workflow_task::TaskError),
23    #[error(transparent)]
24    Callback(#[from] workflow_wasm::callback::CallbackError),
25    #[error("{0}")]
26    JsValue(Printable),
27}
28
29unsafe impl Send for Error {}
30unsafe impl Sync for Error {}
31
32impl<T> From<SendError<T>> for Error {
33    fn from(err: SendError<T>) -> Self {
34        Error::Send(err.to_string())
35    }
36}
37
38impl From<JsValue> for Error {
39    fn from(err: JsValue) -> Self {
40        Error::JsValue(Printable::new(err))
41    }
42}