use std::{ffi::NulError, path::Path};
use thiserror::Error;
use crate::prelude::ScriptContext;
#[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)
}
}
#[derive(Error, Debug)]
pub enum SQFunctionRegistrationError {
#[error("{0} not be registered")]
FailedRegistration(&'static str),
#[error("{0} was attempted to be registered in the wrong context : expected {1} got {2}")]
WrongContext(&'static str, ScriptContext, &'static str),
}
impl SQFunctionRegistrationError {
pub fn log(&self) {
log::error!("{}", self)
}
}
#[derive(Error, Debug)]
pub enum FsOpenError<'a> {
#[error(transparent)]
PathToCstringFailed(#[from] NulError),
#[error("{0} could not convert path to String")]
PathToStringFailed(&'a Path),
#[error("{0} could not be found")]
NotFound(&'a Path),
}
impl FsOpenError<'_> {
pub fn log(&self) {
log::error!("{}", self)
}
}