From 91171852b9d955e3abcb58f9b78f2868db40c8be Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Sun, 12 Mar 2023 19:07:36 +0100 Subject: Avoid exception in PortAudioError.__str__() --- sounddevice.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 = '' + elif host_api < 0: + hostname = f'' + else: + hostname = query_hostapis(host_api)['name'] errormsg = "{}: '{}' [{} error {}]".format( errormsg, hosterror_text, hostname, hosterror_code) -- cgit v1.2.3