daemonic_error 0.1.0

Errors that compose, predict, and leave receipts - Compose: algebraic combination (in active development) - Predict: Glass/Severity - Receipts: audit trail, position, checksum - Reflection: Runtime Reflection through TopologySegment (in active development)
use alloc::string::String;
// use crate::{ctx, ErrorContext, Position};
// use crate::format::ErrorContext;
use core::io;
use crate::daemonic::glass::daemonic_path_buffer::DaemonicPathBuf;

/// OS and syscall-level errors.
/// These wrap POSIX errors with Daemonic context.
/// "daemonic_error" in output is intentional:
/// differentiates Faustian stack from raw POSIX.
#[derive(Debug)]
pub enum OsError {
	Syscall(Syscall),
	// IO(IO),
	File(File),
	Path(Path),
	Permission(Permission),
	Access(Access),
	OutOfMemory(OutOfMemory),
	OutOfSpace(OutOfSpace),
	ResourceBusy(ResourceBusy),
	Signal(Signal),
	Fd(Fd),
	Pid(Pid),
	Mode(Mode),
	Flags(Flags),
	CString(CString),
	Silent(Silent),
}
#[derive(Debug)]
struct Syscall {
	code: i32,
	message: String,
}
// #[derive(Debug)]
// struct IO {
// 	raw_error: io::Error,
// }
#[derive(Debug)]
struct File {
	path: String,
	source: DaemonicPathBuf,
	context: Option<String>,
}
#[derive(Debug)]
struct Path {
	path: String,
	message: String,
}
#[derive(Debug)]
struct Permission {
	permission: String,
}
#[derive(Debug)]
struct Access {
	path: String,
	operation: String,
}
#[derive(Debug)]
struct OutOfMemory {
	path: String,
}
#[derive(Debug)]
struct OutOfSpace {
	path: String,
}
#[derive(Debug)]
struct ResourceBusy {
	resource: String,
}
#[derive(Debug)]
struct Signal {
	sig: String,
}
#[derive(Debug)]
struct Fd {
	message: String,
}
#[derive(Debug)]
struct Pid {
	pid: i32,
}
#[derive(Debug)]
struct Mode {
	message: String,
}
#[derive(Debug)]
struct Flags {
	message: String,
}
#[derive(Debug)]
struct CString;
#[derive(Debug)]
struct Silent {
	code: i32,
}
// impl OsError {
// 	pub fn ctx(&self) -> ErrorContext {
// 		match self {
// 			Self::Syscall { code, message } => ctx!(
// 				"OS",
// 				"Syscall",
// 				format!("errno {}: {}", code, message)
// 				),
//
// 			Self::Io(e) => ctx!("OS", "IO", crate::normalize_io_error(e)),
//
// 			Self::File {
// 				path,
// 				source,
// 				context,
// 			} => {
// 				let base = format!(
// 					"{}: {}",
// 					path,
// 					crate::normalize_io_error(source)
// 				);
// 				match context {
// 					Some(c) => {
// 						ctx!("OS", "File", format!("{}: {}", c, base))
// 					}
// 					None => ctx!("OS", "File", base),
// 				}
// 			}
//
// 			Self::Path { path, message } => {
// 				ctx!("OS", "Path", format!("{}: {}", path, message))
// 			}
//
// 			Self::Permission(path) => {
// 				ctx!("OS", "Permission", format!("denied: {}", path))
// 			}
//
// 			Self::Access { path, operation } => ctx!(
// "OS",
// "Access",
// format!("cannot {} {}: Permission denied", operation, path)
// ),
//
// 			Self::OutOfMemory => ctx!("OS", "Memory", "out of memory"),
//
// 			Self::OutOfSpace { path } => {
// 				ctx!("OS", "Storage", format!("out of space on {}", path))
// 			}
//
// 			Self::ResourceBusy { resource } => {
// 				ctx!("OS", "Resource", format!("{} is busy", resource))
// 			}
//
// 			Self::Signal(msg) => ctx!("OS", "Signal", msg),
//
// 			Self::Fd { message } => ctx!("OS", "FileDescriptor", message),
//
// 			Self::Pid { message } => ctx!("OS", "ProcessId", message),
//
// 			Self::Mode(message) => ctx!("OS", "Mode", message),
//
// 			Self::Flags { message } => ctx!("OS", "Flags", message),
//
// 	 		Self::CString => ctx!(
// "OS",
// "CString",
// "invalid C string (null byte or encoding)"
// ),
//
// 			Self::Silent(_) => ctx!("OS", "Silent", ""),
// 		}
// 	}
//
// 	pub fn code(&self) -> i32 {
// 		match self {
// 			Self::Syscall { code, .. } => *code,
// 			Self::IO(e) => e.raw_os_error().unwrap_or(-1),
// 			Self::Silent(code) => *code,
// 			_ => 1,
// 		}
// 	}
//
// 	pub fn is_silent(&self) -> bool {
// 		matches!(self, Self::Silent(_))
// 	}
//
// 	// Constructors
// 	pub fn from_last_os_error() -> Self {
// 		Self::Io(io::Error::last_os_error())
// 	}
//
// 	pub fn from_errno(code: i32) -> Self {
// 		Self::Syscall {
// 			code,
// 			message: format!("system call failed with errno {}", code),
// 		}
// 	}
//
// 	pub fn file<P: Into<String>, C: Into<String>>(
// 		path: P,
// 		source: io::Error,
// 		context: Option<C>,
// 	) -> Self {
// 		Self::File {
// 			path: path.into(),
// 			source,
// 			context: context.map(|c| c.into()),
// 		}
// 	}
// }
// impl fmt::Display for OsError {
// 	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// 		if self.is_silent() {
// 			return Ok(());
// 		}
// 		write!(f, "{}", self.ctx())
// 	}
// }
// impl std::error::Error for OsError {}
// impl From<io::Error> for OsError {
// 	fn from(e: io::Error) -> Self {
// 		Self::Io(e)
// 	}
// }