Skip to main content

molten_workflow/
error.rs

1//! Defines error types specific to workflow operations within the `molten-workflow` crate.
2//!
3//! This module provides a comprehensive set of error variants encapsulated by
4//! `WorkflowError`, each detailing specific reasons why a workflow operation failed.
5
6use thiserror::Error;
7
8/// Represents errors that can occur during workflow operations.
9#[derive(Error, Debug, PartialEq)]
10pub enum WorkflowError {
11    /// Occurs when a document's associated workflow ID does not match the provided workflow ID.
12    #[error(
13        "Workflow ID mismatch: Document belongs to '{doc_wf}' but provided workflow is '{provided_wf}'"
14    )]
15    WorkflowMismatch {
16        /// Document workflow ID
17        doc_wf: String,
18        /// Provided workflow ID
19        provided_wf: String,
20    },
21
22    /// Occurs when a referenced phase ID does not exist within the workflow definition.
23    #[error("Phase '{0}' does not exist in this workflow")]
24    UnknownPhase(String),
25
26    /// Occurs when an attempted transition from the current phase to a target phase is not allowed by the workflow rules.
27    #[error("Invalid transition: Cannot move from '{current}' to '{target}'")]
28    InvalidTransition {
29        /// Current phase
30        current: String,
31        /// Target phase
32        target: String,
33    },
34
35    /// Occurs when a document does not have a `current_phase` defined, which is required for workflow operations.
36    #[error("Document has no current phase (is it a new document?)")]
37    NoCurrentPhase,
38}