Skip to content

Commit 80f4f0a

Browse files
committed
badfiles: Fix decoding for command output
Probably fixes beetbox#3165. There were several things going wrong here: 1. For some reason, this was using the *filesystem* encoding, which is what you use to decode filenames. But this was general command output, not filenames. 2. Errors in decoding threw exceptions, even though all we do with this output is show it to the user. 3. The prints were using `displayable_path`, even though the lines are *already* Unicode strings. Hopefully this cleans up that mess.
1 parent 3973efc commit 80f4f0a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

beetsplug/badfiles.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def run_command(self, cmd):
6666
status = e.returncode
6767
except OSError as e:
6868
raise CheckerCommandException(cmd, e)
69-
output = output.decode(sys.getfilesystemencoding())
69+
output = output.decode(sys.getdefaultencoding(), 'replace')
7070
return status, errors, [line for line in output.split("\n") if line]
7171

7272
def check_mp3val(self, path):
@@ -134,12 +134,12 @@ def check_item(self, item):
134134
ui.print_(u"{}: checker exited with status {}"
135135
.format(ui.colorize('text_error', dpath), status))
136136
for line in output:
137-
ui.print_(u" {}".format(displayable_path(line)))
137+
ui.print_(u" {}".format(line))
138138
elif errors > 0:
139139
ui.print_(u"{}: checker found {} errors or warnings"
140140
.format(ui.colorize('text_warning', dpath), errors))
141141
for line in output:
142-
ui.print_(u" {}".format(displayable_path(line)))
142+
ui.print_(u" {}".format(line))
143143
elif self.verbose:
144144
ui.print_(u"{}: ok".format(ui.colorize('text_success', dpath)))
145145

docs/changelog.rst

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ Fixes:
147147
Thanks to :user:`Holzhaus`.
148148
:bug:`1579`
149149
* Fetchart now respects the ``ignore`` and ``ignore_hidden`` settings. :bug:`1632`
150+
* :doc:`/plugins/badfiles`: Avoid a crash when the underlying tool emits
151+
undecodable output.
152+
:bug:`3165`
150153

151154
.. _python-itunes: https://github.com/ocelma/python-itunes
152155

0 commit comments

Comments
 (0)