Skip to content

Commit

Permalink
Patch the callback print function to suppress the UnicodeDecodeError (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman authored Aug 5, 2024
1 parent 53114b2 commit 8859ca3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8859ca3

Please sign in to comment.