omega_cognitive_kernel/
error.rs1#[allow(unused_imports)]
2use crate::prelude::*;
3
4use alloc::string::String;
5use core::fmt;
6use uuid::Uuid;
7
8#[derive(Debug)]
23pub enum OmegaError {
24 ConstraintViolation(String),
26 SandboxRejection(String),
28 ExecutionBlocked(String),
30 Memory(String),
32 Persist(String),
34 StepNotExecuted {
36 step_id: Uuid,
38 reason: String,
40 },
41 StepExecutionOutcomeUnknown {
43 step_id: Uuid,
45 reason: String,
47 },
48 StepCommitIncomplete {
50 step_id: Uuid,
52 stage: String,
54 },
55 StepAlreadyCommitted {
57 step_id: Uuid,
59 },
60 StepIdConflict {
62 step_id: Uuid,
64 },
65 Config(String),
67 Other(anyhow::Error),
69}
70
71impl fmt::Display for OmegaError {
72 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73 match self {
74 Self::ConstraintViolation(value) => write!(f, "Constraint violation: {value}"),
75 Self::SandboxRejection(value) => write!(f, "Sandbox rejection: {value}"),
76 Self::ExecutionBlocked(value) => write!(f, "Execution blocked: {value}"),
77 Self::Memory(value) => write!(f, "Memory error: {value}"),
78 Self::Persist(value) => write!(f, "Persistence error: {value}"),
79 Self::StepNotExecuted { step_id, reason } => {
80 write!(f, "Step {step_id} was not executed: {reason}")
81 }
82 Self::StepExecutionOutcomeUnknown { step_id, reason } => write!(
83 f,
84 "Step {step_id} execution outcome is unknown: {reason}; external effects may have occurred"
85 ),
86 Self::StepCommitIncomplete { step_id, stage } => write!(
87 f,
88 "Step {step_id} executed but commit is incomplete at {stage}; do not retry automatically"
89 ),
90 Self::StepAlreadyCommitted { step_id } => write!(
91 f,
92 "Step {step_id} is already committed; duplicate was not executed"
93 ),
94 Self::StepIdConflict { step_id } => write!(
95 f,
96 "Step ID {step_id} was already used with a different goal"
97 ),
98 Self::Config(value) => write!(f, "Config error: {value}"),
99 Self::Other(error) => error.fmt(f),
100 }
101 }
102}
103
104#[cfg(feature = "std")]
105impl std::error::Error for OmegaError {
106 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
107 match self {
108 Self::Other(error) => error.source(),
109 _ => None,
110 }
111 }
112}
113
114impl From<anyhow::Error> for OmegaError {
115 fn from(error: anyhow::Error) -> Self {
116 Self::Other(error)
117 }
118}
119
120pub type Result<T> = core::result::Result<T, OmegaError>;