mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2024-11-22 11:00:47 +00:00
extends error class
now accepts a custom message fn_name and error code stored as class attributes
This commit is contained in:
parent
af368b4b0a
commit
bafaa58507
@ -16,7 +16,7 @@ class CBindings(metaclass=ABCMeta):
|
|||||||
Maps expected ctype argument and res types for each binding.
|
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 = libc.VBVMR_Login
|
||||||
vm_login.restype = LONG
|
vm_login.restype = LONG
|
||||||
@ -116,10 +116,10 @@ class CBindings(metaclass=ABCMeta):
|
|||||||
res = func(*args)
|
res = func(*args)
|
||||||
if ok_exp is None:
|
if ok_exp is None:
|
||||||
if res not in ok:
|
if res not in ok:
|
||||||
raise CAPIError(f"{func.__name__} returned {res}")
|
raise CAPIError(func.__name__, res)
|
||||||
elif not ok_exp(res):
|
elif not ok_exp(res) and res not in ok:
|
||||||
raise CAPIError(f"{func.__name__} returned {res}")
|
raise CAPIError(func.__name__, res)
|
||||||
return res
|
return res
|
||||||
except CAPIError as e:
|
except CAPIError as e:
|
||||||
self.logger_cbindings.exception(f"{type(e).__name__}: {e}")
|
self.logger_cbindings.exception(str(e))
|
||||||
raise
|
raise
|
||||||
|
@ -5,6 +5,15 @@ class InstallError(Exception):
|
|||||||
class CAPIError(Exception):
|
class CAPIError(Exception):
|
||||||
"""Exception raised when the C-API returns error values"""
|
"""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):
|
class VMError(Exception):
|
||||||
"""Exception raised when general errors occur"""
|
"""Exception raised when general errors occur"""
|
||||||
|
Loading…
Reference in New Issue
Block a user