Skip to content

Commit

Permalink
badfiles: Fix decoding for command output
Browse files Browse the repository at this point in the history
Probably fixes #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.
  • Loading branch information
sampsyo committed Feb 24, 2019
1 parent 3973efc commit 80f4f0a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions beetsplug/badfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def run_command(self, cmd):
status = e.returncode
except OSError as e:
raise CheckerCommandException(cmd, e)
output = output.decode(sys.getfilesystemencoding())
output = output.decode(sys.getdefaultencoding(), 'replace')
return status, errors, [line for line in output.split("\n") if line]

def check_mp3val(self, path):
Expand Down Expand Up @@ -134,12 +134,12 @@ def check_item(self, item):
ui.print_(u"{}: checker exited with status {}"
.format(ui.colorize('text_error', dpath), status))
for line in output:
ui.print_(u" {}".format(displayable_path(line)))
ui.print_(u" {}".format(line))
elif errors > 0:
ui.print_(u"{}: checker found {} errors or warnings"
.format(ui.colorize('text_warning', dpath), errors))
for line in output:
ui.print_(u" {}".format(displayable_path(line)))
ui.print_(u" {}".format(line))
elif self.verbose:
ui.print_(u"{}: ok".format(ui.colorize('text_success', dpath)))

Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ Fixes:
Thanks to :user:`Holzhaus`.
:bug:`1579`
* Fetchart now respects the ``ignore`` and ``ignore_hidden`` settings. :bug:`1632`
* :doc:`/plugins/badfiles`: Avoid a crash when the underlying tool emits
undecodable output.
:bug:`3165`

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

Expand Down

0 comments on commit 80f4f0a

Please sign in to comment.