Skip to main content

fluxpro_engine/models/
process_def_error.rs

1//! Errors shared by definition creation, instance startup, and signal submission.
2
3use crate::models::process_id::ProcessId;
4use serde::Serialize;
5use std::fmt::Display;
6
7/// Legacy outcome wrapper for definition creation.
8pub enum CreateProcessResult {
9    /// Successful completion carrying its result or context patch.
10    Success(ProcessId),
11    /// An operation failed; associated data describes the failure.
12    Error(CreateProcessError),
13}
14
15/// Definition, startup, persistence, or signal admission failure.
16#[derive(Debug, Serialize)]
17pub enum CreateProcessError {
18    /// The definition could not be compiled.
19    CompilationError,
20    /// Accumulated structural definition errors.
21    ValidationError(Vec<String>),
22    /// Persistence failure with a diagnostic message.
23    DbError(String),
24    /// No usable definition or required startup declaration was found.
25    ProcessDefNotFound,
26    /// The process key failed validation.
27    ProcessKeyNotValid,
28    /// The stored version is malformed.
29    ProcessVersionNotValid,
30    /// The lifecycle status failed validation.
31    StatusNotValid,
32    /// Definition metadata failed validation.
33    MetadataNotValid,
34    /// The complete stored definition could not be decoded.
35    FullDefinitionNotValid,
36    /// The process instance could not be created.
37    RunProcessError,
38    /// The business process ID is already in use.
39    ProcessIdNonUnique,
40    /// Signal admission or queue insertion failed.
41    CreateSignalError(String),
42    /// The signal is neither declared nor referenced by a compatible wait node.
43    SignalNotExists,
44}
45
46#[cfg(feature = "db")]
47impl From<sqlx::Error> for CreateProcessError {
48    fn from(value: sqlx::Error) -> Self {
49        CreateProcessError::DbError(format!("db_error: {}", value))
50    }
51}
52
53impl Display for CreateProcessError {
54    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55        write!(f, "{:?}", self)
56    }
57}