Skip to main content

temporalio_sdk/
error.rs

1//! Shared SDK error re-exports.
2
3pub use crate::workflow_registry::WorkflowRegistrationError;
4#[cfg(feature = "experimental")]
5use temporalio_client::PluginApplyError;
6use temporalio_sdk_core::WorkerValidationError as CoreWorkerValidationError;
7
8/// Errors that can occur while creating an SDK runtime.
9#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum RuntimeError {
12    /// Runtime initialization failed.
13    #[error("runtime initialization failed: {0}")]
14    Initialization(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
15    /// No Tokio runtime is active on the current thread.
16    #[error("no Tokio runtime is active on the current thread")]
17    NoCurrentTokioRuntime,
18}
19
20impl RuntimeError {
21    pub(crate) fn from_core(error: anyhow::Error) -> Self {
22        Self::Initialization(error.into_boxed_dyn_error())
23    }
24}
25
26/// Errors encountered while validating a worker before polling begins.
27#[derive(Debug, thiserror::Error)]
28#[non_exhaustive]
29pub enum WorkerValidationError {
30    /// The configured namespace could not be described.
31    #[error("namespace {namespace} was not found or otherwise could not be described: {source}")]
32    NamespaceDescribeError {
33        /// The underlying server error.
34        #[source]
35        source: temporalio_client::tonic::Status,
36        /// The namespace that could not be described.
37        namespace: String,
38    },
39}
40
41impl WorkerValidationError {
42    pub(crate) fn from_core(error: CoreWorkerValidationError) -> Self {
43        match error {
44            CoreWorkerValidationError::NamespaceDescribeError { source, namespace } => {
45                Self::NamespaceDescribeError { source, namespace }
46            }
47        }
48    }
49}
50
51/// Errors that can occur while creating a worker.
52///
53/// **Experimental:** This API may change or be removed.
54#[derive(Debug, thiserror::Error)]
55#[non_exhaustive]
56pub enum WorkerCreateError {
57    /// A plugin failed while configuring worker options.
58    #[cfg(feature = "experimental")]
59    #[error(transparent)]
60    Plugin(#[from] PluginApplyError),
61    /// Worker initialization failed after plugin configuration completed.
62    #[error("worker initialization failed: {0}")]
63    Initialization(#[source] anyhow::Error),
64}
65
66/// Errors that can occur while running a worker.
67#[derive(Debug, thiserror::Error)]
68#[non_exhaustive]
69pub enum WorkerRunError {
70    /// Worker validation failed before polling began.
71    #[error("worker validation failed: {0}")]
72    Validation(#[source] WorkerValidationError),
73    /// An unrecoverable error occurred while running the worker.
74    #[error("{message}")]
75    Fatal {
76        /// Worker operation that could not continue.
77        message: String,
78        /// Underlying cause.
79        #[source]
80        source: Box<dyn std::error::Error + Send + Sync + 'static>,
81    },
82}
83
84pub use temporalio_common::error::{
85    ActivityExecutionError, ApplicationErrorCategory, ApplicationFailure,
86    CancelExternalWorkflowError, ChildWorkflowExecutionError, ChildWorkflowStartError,
87    OutgoingActivityError, OutgoingError, OutgoingWorkflowError, RetryState, TimeoutType,
88    WorkflowSignalError,
89};