omega_cognitive_kernel/
error.rs1#[allow(unused_imports)]
2use crate::prelude::*;
3
4use alloc::string::String;
5use core::fmt;
6
7#[derive(Debug)]
8pub enum OmegaError {
9 ConstraintViolation(String),
10 SandboxRejection(String),
11 ExecutionBlocked(String),
12 Memory(String),
13 Persist(String),
14 Config(String),
15 Other(anyhow::Error),
16}
17
18impl fmt::Display for OmegaError {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 match self {
21 Self::ConstraintViolation(value) => write!(f, "Constraint violation: {value}"),
22 Self::SandboxRejection(value) => write!(f, "Sandbox rejection: {value}"),
23 Self::ExecutionBlocked(value) => write!(f, "Execution blocked: {value}"),
24 Self::Memory(value) => write!(f, "Memory error: {value}"),
25 Self::Persist(value) => write!(f, "Persistence error: {value}"),
26 Self::Config(value) => write!(f, "Config error: {value}"),
27 Self::Other(error) => error.fmt(f),
28 }
29 }
30}
31
32#[cfg(feature = "std")]
33impl std::error::Error for OmegaError {
34 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
35 match self {
36 Self::Other(error) => error.source(),
37 _ => None,
38 }
39 }
40}
41
42impl From<anyhow::Error> for OmegaError {
43 fn from(error: anyhow::Error) -> Self {
44 Self::Other(error)
45 }
46}
47
48pub type Result<T> = core::result::Result<T, OmegaError>;