1use sayiir_core::error::{BoxError, BuildError, BuildErrors, CodecError, WorkflowError};
4use sayiir_persistence::BackendError;
5
6#[derive(Debug, thiserror::Error)]
11pub enum RuntimeError {
12 #[error(transparent)]
14 Workflow(#[from] WorkflowError),
15
16 #[error(transparent)]
18 Build(#[from] BuildErrors),
19
20 #[error(transparent)]
22 Backend(#[from] BackendError),
23
24 #[error(transparent)]
26 Codec(#[from] CodecError),
27
28 #[error(transparent)]
30 Task(BoxError),
31
32 #[error(transparent)]
34 Join(#[from] tokio::task::JoinError),
35
36 #[error("Workflow instance already exists: {0}")]
38 InstanceAlreadyExists(String),
39}
40
41impl From<BoxError> for RuntimeError {
42 fn from(err: BoxError) -> Self {
43 match err.downcast::<CodecError>() {
44 Ok(codec_err) => Self::Codec(*codec_err),
45 Err(other) => Self::Task(other),
46 }
47 }
48}
49
50impl From<BuildError> for RuntimeError {
51 fn from(error: BuildError) -> Self {
52 Self::Build(BuildErrors::from(error))
53 }
54}
55
56impl RuntimeError {
57 #[must_use]
59 pub fn is_timeout(&self) -> bool {
60 matches!(self, Self::Workflow(WorkflowError::TaskTimedOut { .. }))
61 }
62
63 #[must_use]
65 pub fn is_decode_error(&self) -> bool {
66 matches!(self, Self::Codec(CodecError::DecodeFailed { .. }))
67 }
68}