diff --git a/voicemeeterlib/cbindings.py b/voicemeeterlib/cbindings.py index 87413a9..cd2cc4f 100644 --- a/voicemeeterlib/cbindings.py +++ b/voicemeeterlib/cbindings.py @@ -16,7 +16,7 @@ class CBindings(metaclass=ABCMeta): Maps expected ctype argument and res types for each binding. """ - logger_cbindings = logger.getChild("Cbindings") + logger_cbindings = logger.getChild("CBindings") vm_login = libc.VBVMR_Login vm_login.restype = LONG @@ -116,10 +116,10 @@ class CBindings(metaclass=ABCMeta): res = func(*args) if ok_exp is None: if res not in ok: - raise CAPIError(f"{func.__name__} returned {res}") - elif not ok_exp(res): - raise CAPIError(f"{func.__name__} returned {res}") + raise CAPIError(func.__name__, res) + elif not ok_exp(res) and res not in ok: + raise CAPIError(func.__name__, res) return res except CAPIError as e: - self.logger_cbindings.exception(f"{type(e).__name__}: {e}") + self.logger_cbindings.exception(str(e)) raise diff --git a/voicemeeterlib/error.py b/voicemeeterlib/error.py index 11aeb09..f51e4e1 100644 --- a/voicemeeterlib/error.py +++ b/voicemeeterlib/error.py @@ -5,6 +5,15 @@ class InstallError(Exception): class CAPIError(Exception): """Exception raised when the C-API returns error values""" + def __init__(self, fn_name, code, msg=None): + self.fn_name = fn_name + self.code = code + self.message = msg if msg else f"{fn_name} returned {code}" + super().__init__(self.message) + + def __str__(self): + return f"{type(self).__name__}: {self.message}" + class VMError(Exception): """Exception raised when general errors occur"""