Skip to content

Commit e4f7e6d

Browse files
committed
Handle unicode decode errors gracefully
1 parent c7680db commit e4f7e6d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/sgui/widgets/hardware_dialog.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
from sglib.lib.process import run_process
2121
from sglib.math import clip_value
2222
from sgui import sgqt
23+
2324
import ctypes
25+
import locale
2426
import os
2527
import sys
2628
import time
@@ -412,7 +414,21 @@ def f_close_event(a_self=None, a_event=None):
412414
LOG.info("Enumerating audio devices")
413415
for i in range(f_count):
414416
f_dev = self.pyaudio.Pa_GetDeviceInfo(i)
415-
f_dev_name = f_dev.contents.name.decode(TEXT_ENCODING)
417+
try:
418+
f_dev_name = f_dev.contents.name.decode(TEXT_ENCODING)
419+
except Exception as ex:
420+
try:
421+
dev_name = f_dev.contents.name.decode(
422+
TEXT_ENCODING,
423+
errors='replace',
424+
)
425+
except Exception as ex2:
426+
dev_name = str(ex2)
427+
LOG.error(
428+
f"{host_api_name}: Unable to decode a device name: {ex}, "
429+
f"{locale.getlocale()}, {dev_name}"
430+
)
431+
continue
416432
host_api_name = host_api_dict[f_dev.contents.hostApi]
417433
LOG.info(
418434
f"{i}: {host_api_name}: {f_dev_name} "

0 commit comments

Comments
 (0)