Merge branch 'fiete201-unicode-error'
This commit is contained in:
commit
36bb8f5f5a
@ -191,6 +191,7 @@ Contributors, sorted by the number of commits in descending order:
|
|||||||
* Michael Hoang
|
* Michael Hoang
|
||||||
* Liam BEGUIN
|
* Liam BEGUIN
|
||||||
* Julie Engel
|
* Julie Engel
|
||||||
|
* Fritz Reichwald
|
||||||
* skinnay
|
* skinnay
|
||||||
* Zach-Button
|
* Zach-Button
|
||||||
* Tomasz Kramkowski
|
* Tomasz Kramkowski
|
||||||
@ -199,7 +200,6 @@ Contributors, sorted by the number of commits in descending order:
|
|||||||
* Nikolay Amiantov
|
* Nikolay Amiantov
|
||||||
* Ismail S
|
* Ismail S
|
||||||
* Halfwit
|
* Halfwit
|
||||||
* Fritz Reichwald
|
|
||||||
* David Vogt
|
* David Vogt
|
||||||
* Claire Cavanaugh
|
* Claire Cavanaugh
|
||||||
* rikn00
|
* rikn00
|
||||||
|
@ -65,9 +65,13 @@ class _QtFIFOReader(QObject):
|
|||||||
"""(Try to) read a line from the FIFO."""
|
"""(Try to) read a line from the FIFO."""
|
||||||
log.procs.debug("QSocketNotifier triggered!")
|
log.procs.debug("QSocketNotifier triggered!")
|
||||||
self._notifier.setEnabled(False)
|
self._notifier.setEnabled(False)
|
||||||
for line in self._fifo:
|
try:
|
||||||
self.got_line.emit(line.rstrip('\r\n'))
|
for line in self._fifo:
|
||||||
self._notifier.setEnabled(True)
|
self.got_line.emit(line.rstrip('\r\n'))
|
||||||
|
self._notifier.setEnabled(True)
|
||||||
|
except UnicodeDecodeError as e:
|
||||||
|
log.misc.error("Invalid unicode in userscript output: {}"
|
||||||
|
.format(e))
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
"""Clean up so the FIFO can be closed."""
|
"""Clean up so the FIFO can be closed."""
|
||||||
@ -289,6 +293,9 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner):
|
|||||||
self.got_cmd.emit(line.rstrip())
|
self.got_cmd.emit(line.rstrip())
|
||||||
except OSError:
|
except OSError:
|
||||||
log.procs.exception("Failed to read command file!")
|
log.procs.exception("Failed to read command file!")
|
||||||
|
except UnicodeDecodeError as e:
|
||||||
|
log.misc.error("Invalid unicode in userscript output: {}"
|
||||||
|
.format(e))
|
||||||
|
|
||||||
super()._cleanup()
|
super()._cleanup()
|
||||||
self.finished.emit()
|
self.finished.emit()
|
||||||
|
@ -227,6 +227,24 @@ def test_temporary_files_failed_cleanup(caplog, qtbot, py_proc, runner):
|
|||||||
assert caplog.records[0].message.startswith(expected)
|
assert caplog.records[0].message.startswith(expected)
|
||||||
|
|
||||||
|
|
||||||
|
def test_unicode_error(caplog, qtbot, py_proc, runner):
|
||||||
|
cmd, args = py_proc(r"""
|
||||||
|
import os
|
||||||
|
with open(os.environ['QUTE_FIFO'], 'wb') as f:
|
||||||
|
f.write(b'\x80')
|
||||||
|
""")
|
||||||
|
with caplog.at_level(logging.ERROR):
|
||||||
|
with qtbot.waitSignal(runner.finished, timeout=10000):
|
||||||
|
runner.prepare_run(cmd, *args)
|
||||||
|
runner.store_text('')
|
||||||
|
runner.store_html('')
|
||||||
|
|
||||||
|
assert len(caplog.records) == 1
|
||||||
|
expected = ("Invalid unicode in userscript output: 'utf-8' codec can't "
|
||||||
|
"decode byte 0x80 in position 0: invalid start byte")
|
||||||
|
assert caplog.records[0].message == expected
|
||||||
|
|
||||||
|
|
||||||
def test_unsupported(monkeypatch, tabbed_browser_stubs):
|
def test_unsupported(monkeypatch, tabbed_browser_stubs):
|
||||||
monkeypatch.setattr(userscripts.os, 'name', 'toaster')
|
monkeypatch.setattr(userscripts.os, 'name', 'toaster')
|
||||||
with pytest.raises(userscripts.UnsupportedError) as excinfo:
|
with pytest.raises(userscripts.UnsupportedError) as excinfo:
|
||||||
|
Loading…
Reference in New Issue
Block a user