@@ -107,7 +107,7 @@ def on_core_stdout_read_ready(self):
107
107
return
108
108
109
109
raw_output = bytes (self .core_process .readAllStandardOutput ())
110
- self .last_core_stdout_output = raw_output . decode ( "utf-8" ).strip ()
110
+ self .last_core_stdout_output = self . decode_raw_core_output ( raw_output ).strip ()
111
111
112
112
try :
113
113
print (self .last_core_stdout_output ) # print core output # noqa: T001
@@ -121,7 +121,7 @@ def on_core_stderr_read_ready(self):
121
121
return
122
122
123
123
raw_output = bytes (self .core_process .readAllStandardError ())
124
- self .last_core_stderr_output = raw_output . decode ( "utf-8" ).strip ()
124
+ self .last_core_stderr_output = self . decode_raw_core_output ( raw_output ).strip ()
125
125
126
126
try :
127
127
print (self .last_core_stderr_output , file = sys .stderr ) # print core output # noqa: T001
@@ -162,3 +162,14 @@ def on_core_finished(self, exit_code, exit_status):
162
162
self .events_manager .connect_timer .stop ()
163
163
164
164
raise CoreCrashedError (error_message )
165
+
166
+ @staticmethod
167
+ def decode_raw_core_output (output : bytes ) -> str :
168
+ try :
169
+ # Let's optimistically try to decode from UTF8.
170
+ # If it is not UTF8, we should get UnicodeDecodeError "invalid continuation byte".
171
+ return output .decode ('utf-8' )
172
+ except UnicodeDecodeError :
173
+ # It may be hard to guess the real encoding on some systems,
174
+ # but by using the "backslashreplace" error handler we can keep all the received data.
175
+ return output .decode ('ascii' , errors = 'backslashreplace' )
0 commit comments