From 1de634ffa1598162a2aba152d97f780638c0feac Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Tue, 19 Mar 2024 23:13:15 +0100 Subject: [PATCH] Make the reporting functions a bit more robust Sometimes, non-ASCII characters might appear in message strings, causing a UTF-8 decoding error. Catch it, so the remainder can proceed. --- src/swigtest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/swigtest.py b/src/swigtest.py index 27bcdd75..ddf0f442 100644 --- a/src/swigtest.py +++ b/src/swigtest.py @@ -177,10 +177,14 @@ def msg_callback(target: str, lno: int, fname: str, func: str, elif (msgmode & ad.MSG2_INDENT2) != 0: s = (len(ad.cvar.progname) + 2) * ' ' s += msg - print(s, end='') + try: + print(s, end='') + except UnicodeDecodeError: + print("message contained invalid characters") # very simplified progress callback global prog_hdr +prog_hdr = "" def progress_callback(percent: int, etime: float, hdr: str, finish: int): if hdr: global prog_hdr