Protect against decoding errors with subprocess text mode
All these are calling subprocess in 'text mode', where it will try to decode stdout/stderr using the default encoding (utf-8 for us). If it doesn't decode, subprocess will raise an exception and kobo doesn't handle it, it just passes it along to us, so things blow up - see https://pagure.io/releng/issue/12474 . To avoid this, let's set `errors="replace"`, which tells the decoder to replace invalid data with ? characters. This way we should get as much of the output as can be read, and no crashes. We also replace `universal_newlines=True` with `text=True` as the latter is shorter, clearer, and what Python 3 subprocess wants us to use, it considers `universal_newlines` to just be a backwards-compatibility thing - "The universal_newlines argument is equivalent to text and is provided for backwards compatibility" Signed-off-by: Adam Williamson <awilliam@redhat.com> Merges: https://pagure.io/pungi/pull-request/1812
This commit is contained in:
parent
98e3b3f8c4
commit
2d16a3af00
17 changed files with 132 additions and 70 deletions
|
|
@ -34,7 +34,7 @@ class TestSh(unittest.TestCase):
|
|||
patch_iso.sh(log, ["ls"], foo="bar")
|
||||
self.assertEqual(
|
||||
mock_run.call_args_list,
|
||||
[mock.call(["ls"], foo="bar", universal_newlines=True)],
|
||||
[mock.call(["ls"], foo="bar", text=True, errors="replace")],
|
||||
)
|
||||
self.assertEqual(log.info.call_args_list, [mock.call("Running: %s", "ls")])
|
||||
self.assertEqual(log.debug.call_args_list, [mock.call("%s", "ok")])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue