summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Geier <Matthias.Geier@gmail.com>2023-03-12 19:07:36 +0100
committerMatthias Geier <Matthias.Geier@gmail.com>2023-03-12 19:35:56 +0100
commit91171852b9d955e3abcb58f9b78f2868db40c8be (patch)
treed4b77f464596746d68e7b45f1ce1339800752b88
parentf148dc64c9eb043adcf8de3b34890e8f3df71636 (diff)
Avoid exception in PortAudioError.__str__()
-rw-r--r--sounddevice.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/sounddevice.py b/sounddevice.py
index a94f43b..fe8ca12 100644
--- a/sounddevice.py
+++ b/sounddevice.py
@@ -2223,7 +2223,12 @@ class PortAudioError(Exception):
errormsg = f'{errormsg} [PaErrorCode {self.args[1]}]'
if len(self.args) > 2:
host_api, hosterror_code, hosterror_text = self.args[2]
- hostname = query_hostapis(host_api)['name']
+ if host_api == _lib.paHostApiNotFound:
+ hostname = '<host API not found>'
+ elif host_api < 0:
+ hostname = f'<error getting host API: {host_api}>'
+ else:
+ hostname = query_hostapis(host_api)['name']
errormsg = "{}: '{}' [{} error {}]".format(
errormsg, hosterror_text, hostname, hosterror_code)