use std::ffi::NulError;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum RegisterError {
#[error("some attribute contained a null char")]
InvalidCString(#[from] NulError),
#[error("A core function from c++ is null")]
NoneFunction,
#[error("A builder function returned None")]
NoneResult,
}
impl RegisterError {
pub fn log(&self) {
log::error!("{}", self)
}
}
#[derive(Error, Debug)]
pub enum CVarQueryError {
#[error("some attribute contained a null char")]
InvalidCString(#[from] NulError),
#[error("the requested cvar doesn't exist")]
NotFound,
#[error("the cvar interface doesn't exists yet?")]
NoCVarInterface,
}
impl CVarQueryError {
pub fn log(&self) {
log::error!("{}", self)
}
}
#[derive(Error, Debug)]
pub enum CallError {
#[error("function string contained a null char")]
InvalidFunctionCString(#[from] NulError),
#[error("{0} function wasn't found on the sqvm; is it global?")]
FunctionNotFound(String),
#[error("function failed to execute")]
FunctionFailedToExecute,
}
impl CallError {
pub fn log(&self) {
log::error!("{}", self)
}
}
#[derive(Error, Debug)]
pub enum SQCompileError {
#[error("provided code failed to compile")]
CompileError,
#[error("compiled buffer failed to execute")]
BufferFailedToExecute,
}
impl SQCompileError {
pub fn log(&self) {
log::error!("{}", self)
}
}
#[derive(Error, Debug, Default, PartialEq)]
pub enum CStringPtrError {
#[default]
#[error("literally nothing like the pointer is null")]
None,
#[error("invalid string (0)")]
Utf8Error(#[from] std::str::Utf8Error),
}
impl CStringPtrError {
pub fn log(&self) {
log::error!("{}", self)
}
}
#[derive(Error, Debug)]
pub enum CompletionError {
#[error("no more completion slots remain")]
NoCompletionSlotsLeft,
}
impl CompletionError {
pub fn log(&self) {
log::error!("{}", self)
}
}
#[derive(Error, Debug)]
pub enum InterfaceGetterError<'a> {
#[error(transparent)]
InvalidFunctionCString(#[from] NulError),
#[error("dll {0} doesn't have a create interface function")]
NullCreateInterface(usize),
#[error(transparent)]
WinApiError(#[from] windows::core::Error),
#[error("{0} wasn't found in the module; check the name or dll name")]
InterfaceNotFound(&'a str),
}
impl InterfaceGetterError<'_> {
pub fn log(&self) {
log::error!("{}", self)
}
}