Compare commits

..

No commits in common. "ce7cda100fe810f550857c5450e13f010fb43d1e" and "5aaa9aab715fbbdfc827e4b01612a999ebc09e23" have entirely different histories.

7 changed files with 37 additions and 44 deletions

View File

@ -11,24 +11,6 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
- [x]
## [2.4.8] - 2023-08-13
### Added
- Error tests added in tests/test_errors.py
- fn_name and code set as class attributes for CAPIError
- Errors section in README updated.
### Changed
- InstallError and CAPIError classes now subclass VMError
## [2.3.7] - 2023-08-01
### Changed
- If the configs loader is passed an invalid config TOML it will log an error but continue to load further configs into memory.
## [2.3.2] - 2023-07-12
### Added

View File

@ -845,10 +845,7 @@ True iff a level has been updated.
- `errors.VMError`: Exception raised when general errors occur.
- `errors.InstallError`: Exception raised when installation errors occur.
- `errors.CAPIError`: Exception raised when the C-API returns error values.
- The following attributes are available:
- `fn_name`: C-API function name.
- `code`: error code
- For a full list of error codes check the [VoicemeeterRemote header file][Voicemeeter Remote Header].
- Error codes are stored in {Exception Class}.code. For a full list of error codes [check the VoicemeeterRemote header file][Voicemeeter Remote Header].
### Logging

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "voicemeeter-api"
version = "2.4.8"
version = "2.4.7"
description = "A Python wrapper for the Voiceemeter API"
authors = ["onyx-and-iris <code@onyxandiris.online>"]
license = "MIT"

View File

@ -1,5 +1,3 @@
import re
import pytest
import voicemeeterlib
@ -32,12 +30,12 @@ class TestErrors:
"No config with name 'unknown' is loaded into memory",
f"Known configs: {list(vm.configs.keys())}",
)
with pytest.raises(
voicemeeterlib.error.VMError, match=re.escape("\n".join(EXPECTED_MSG))
):
with pytest.raises(voicemeeterlib.error.VMError) as exc_info:
vm.apply_config("unknown")
e = exc_info.value
assert e.message == "\n".join(EXPECTED_MSG)
def test_it_tests_an_invalid_config_key(self):
CONFIG = {
"strip-0": {"A1": True, "B1": True, "gain": -6.0},

View File

@ -121,5 +121,5 @@ class CBindings(metaclass=ABCMeta):
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

View File

@ -1,6 +1,13 @@
class VMError(Exception):
"""Base VM Exception class. Raised when general errors occur."""
def __init__(self, msg):
self.message = msg
super().__init__(self.message)
def __str__(self):
return f"{type(self).__name__}: {self.message}"
class InstallError(VMError):
"""Exception raised when installation errors occur"""
@ -9,16 +16,7 @@ class InstallError(VMError):
class CAPIError(VMError):
"""Exception raised when the C-API returns an error code"""
def __init__(self, fn_name, code):
def __init__(self, fn_name, code, msg=None):
self.fn_name = fn_name
self.code = code
if self.code == -9:
message = " ".join(
(
f"no bind for {self.fn_name}.",
"are you using an old version of the API?",
)
)
else:
message = f"{self.fn_name} returned {self.code}"
super().__init__(message)
super(CAPIError, self).__init__(msg if msg else f"{fn_name} returned {code}")

View File

@ -121,7 +121,13 @@ class Remote(CBindings):
return self.call(self.bind_macro_button_is_dirty, ok=(0, 1)) == 1
except AttributeError as e:
self.logger.exception(f"{type(e).__name__}: {e}")
raise CAPIError("VBVMR_MacroButton_IsDirty", -9) from e
ERR_MSG = (
"no bind for VBVMR_MacroButton_IsDirty.",
"are you using an old version of the API?",
)
raise CAPIError(
"VBVMR_MacroButton_IsDirty", -9, msg=" ".join(ERR_MSG)
) from e
@property
def ldirty(self) -> bool:
@ -181,7 +187,13 @@ class Remote(CBindings):
)
except AttributeError as e:
self.logger.exception(f"{type(e).__name__}: {e}")
raise CAPIError("VBVMR_MacroButton_GetStatus", -9) from e
ERR_MSG = (
"no bind for VBVMR_MacroButton_GetStatus.",
"are you using an old version of the API?",
)
raise CAPIError(
"VBVMR_MacroButton_GetStatus", -9, msg=" ".join(ERR_MSG)
) from e
return int(c_state.value)
def set_buttonstatus(self, id_: int, val: int, mode: int) -> None:
@ -196,7 +208,13 @@ class Remote(CBindings):
)
except AttributeError as e:
self.logger.exception(f"{type(e).__name__}: {e}")
raise CAPIError("VBVMR_MacroButton_SetStatus", -9) from e
ERR_MSG = (
"no bind for VBVMR_MacroButton_SetStatus.",
"are you using an old version of the API?",
)
raise CAPIError(
"VBVMR_MacroButton_SetStatus", -9, msg=" ".join(ERR_MSG)
) from e
self.cache[f"mb_{id_}_{mode}"] = int(c_state.value)
def get_num_devices(self, direction: str = None) -> int: