mirror of
https://github.com/onyx-and-iris/nvda-addon-voicemeeter.git
synced 2026-03-20 20:09:11 +00:00
rename exceptions + lint fixes
This commit is contained in:
parent
8e8e3ce8a5
commit
8b025206b1
@ -2,7 +2,7 @@ import ctypes as ct
|
||||
from ctypes.wintypes import CHAR, FLOAT, LONG
|
||||
|
||||
from .cdll import libc
|
||||
from .error import VMCAPIError
|
||||
from .error import VMAddonCAPIError
|
||||
|
||||
|
||||
class Binds:
|
||||
@ -41,5 +41,5 @@ class Binds:
|
||||
def call(self, fn, *args, ok=(0,)):
|
||||
retval = fn(*args)
|
||||
if retval not in ok:
|
||||
raise VMCAPIError(fn.__name__, retval)
|
||||
raise VMAddonCAPIError(fn.__name__, retval)
|
||||
return retval
|
||||
|
||||
@ -1,16 +1,22 @@
|
||||
import ctypes as ct
|
||||
import platform
|
||||
import winreg
|
||||
from pathlib import Path
|
||||
|
||||
from .error import VMError
|
||||
from .error import VMAddonError
|
||||
|
||||
try:
|
||||
import winreg
|
||||
except ImportError as e:
|
||||
ERR_MSG = 'winreg module not found, only Windows OS supported'
|
||||
raise VMAddonError(ERR_MSG) from e
|
||||
|
||||
# Defense against edge cases where winreg imports but we're not on Windows
|
||||
if platform.system() != 'Windows':
|
||||
ERR_MSG = f'Unsupported OS: {platform.system()}, only Windows OS supported'
|
||||
raise VMAddonError(ERR_MSG)
|
||||
|
||||
BITS = 64 if ct.sizeof(ct.c_voidp) == 8 else 32
|
||||
|
||||
if platform.system() != 'Windows':
|
||||
raise VMError('Only Windows OS supported')
|
||||
|
||||
|
||||
VM_KEY = 'VB:Voicemeeter {17359A74-1236-5467}'
|
||||
REG_KEY = '\\'.join(
|
||||
filter(
|
||||
@ -35,12 +41,14 @@ def get_vmpath():
|
||||
try:
|
||||
vm_parent = Path(get_vmpath()).parent
|
||||
except FileNotFoundError as e:
|
||||
raise VMError('Unable to fetch DLL path from the registry') from e
|
||||
ERR_MSG = 'Voicemeeter installation not found in registry'
|
||||
raise VMAddonError(ERR_MSG) from e
|
||||
|
||||
DLL_NAME = f'VoicemeeterRemote{"64" if BITS == 64 else ""}.dll'
|
||||
|
||||
dll_path = vm_parent.joinpath(DLL_NAME)
|
||||
if not dll_path.is_file():
|
||||
raise VMError(f'Could not find {dll_path}')
|
||||
ERR_MSG = f'Could not find {dll_path}'
|
||||
raise VMAddonError(ERR_MSG)
|
||||
|
||||
libc = ct.WinDLL(str(dll_path))
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
class VMError(Exception):
|
||||
"""Base voicemeeterlib exception class"""
|
||||
class VMAddonError(Exception):
|
||||
"""Base voicemeeter add-on exception class"""
|
||||
|
||||
|
||||
class VMCAPIError(VMError):
|
||||
"""Exception raised when the C-API returns an error code"""
|
||||
class VMAddonCAPIError(VMAddonError):
|
||||
"""Exception raised when the Voicemeeter C-API returns an error code"""
|
||||
|
||||
def __init__(self, fn_name, code):
|
||||
self.fn_name = fn_name
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum, unique
|
||||
|
||||
from .error import VMError
|
||||
from .error import VMAddonError
|
||||
|
||||
|
||||
@unique
|
||||
@ -78,7 +78,8 @@ def kind_factory(kind_id):
|
||||
elif kind_id == 'potato':
|
||||
_kind_map = PotatoMap
|
||||
else:
|
||||
raise ValueError(f'Unknown Voicemeeter kind {kind_id}')
|
||||
ERR_MSG = f'Unknown Voicemeeter kind {kind_id}'
|
||||
raise ValueError(ERR_MSG)
|
||||
return _kind_map(name=kind_id)
|
||||
|
||||
|
||||
@ -87,5 +88,5 @@ def request_kind_map(kind_id):
|
||||
try:
|
||||
KIND_obj = kind_factory(kind_id)
|
||||
except ValueError as e:
|
||||
raise VMError(str(e)) from e
|
||||
raise VMAddonError(str(e)) from e
|
||||
return KIND_obj
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user