JDevlieghere created this revision.
JDevlieghere added reviewers: LLDB, aprantl, davide.
JDevlieghere added a reviewer: labath.
JDevlieghere updated this revision to Diff 253229.
JDevlieghere added a comment.

Use single quotes for consistency


Fixes a UnicodeDecodeError when stdout or stderr contain non-ASCI characters.

      output += """Command Output (stdout):\n--\n%s\n--\n""" % (out,)
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 721: 
ordinal not in range(128)


https://reviews.llvm.org/D76955

Files:
  lldb/test/API/lldbtest.py


Index: lldb/test/API/lldbtest.py
===================================================================
--- lldb/test/API/lldbtest.py
+++ lldb/test/API/lldbtest.py
@@ -82,7 +82,7 @@
                     sys.executable,
                     '-c',
                     'import sys; print(sys.executable)'
-                ]).decode('utf-8').strip()
+                ]).decode('utf-8', errors='ignore').strip()
                 shutil.copy(python, copied_python)
             cmd[0] = copied_python
 
@@ -99,6 +99,10 @@
             timeoutInfo = 'Reached timeout of {} seconds'.format(
                 litConfig.maxIndividualTestTime)
 
+        # Decode stdout and stderr as it might contains UTF-8 characters.
+        out = out.decode('utf-8', errors='ignore')
+        err = err.decode('utf-8', errors='ignore')
+
         output = """Script:\n--\n%s\n--\nExit Code: %d\n""" % (
             ' '.join(cmd), exitCode)
         if timeoutInfo is not None:


Index: lldb/test/API/lldbtest.py
===================================================================
--- lldb/test/API/lldbtest.py
+++ lldb/test/API/lldbtest.py
@@ -82,7 +82,7 @@
                     sys.executable,
                     '-c',
                     'import sys; print(sys.executable)'
-                ]).decode('utf-8').strip()
+                ]).decode('utf-8', errors='ignore').strip()
                 shutil.copy(python, copied_python)
             cmd[0] = copied_python
 
@@ -99,6 +99,10 @@
             timeoutInfo = 'Reached timeout of {} seconds'.format(
                 litConfig.maxIndividualTestTime)
 
+        # Decode stdout and stderr as it might contains UTF-8 characters.
+        out = out.decode('utf-8', errors='ignore')
+        err = err.decode('utf-8', errors='ignore')
+
         output = """Script:\n--\n%s\n--\nExit Code: %d\n""" % (
             ' '.join(cmd), exitCode)
         if timeoutInfo is not None:
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to