From 14aaba8764c57e12f52ea0d8414f6140b383dc23 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sun, 4 Aug 2024 11:20:44 +0800 Subject: [PATCH] Patch the callback print function to suppress the UnicodeDecodeError --- pygmt/clib/session.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index 829381d339d..a0c11373d68 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -379,10 +379,14 @@ def print_func(file_pointer, message): # noqa: ARG001 We'll capture the messages and print them to stderr so that they will show up on the Jupyter notebook. """ - message = message.decode().strip() + # Have to use try..except due to upstream GMT bug in GMT <= 6.5.0. + # See https://github.com/GenericMappingTools/pygmt/issues/3205. + try: + message = message.decode().strip() + except UnicodeDecodeError: + return 0 self._error_log.append(message) - # flush to make sure the messages are printed even if we have a - # crash. + # Flush to make sure the messages are printed even if we have a crash. print(message, file=sys.stderr, flush=True) # noqa: T201 return 0