From 80f4f0a0f235b9764f516990c174f6b73695175b Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sun, 24 Feb 2019 16:06:36 -0500 Subject: [PATCH] badfiles: Fix decoding for command output 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. --- beetsplug/badfiles.py | 6 +++--- docs/changelog.rst | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/beetsplug/badfiles.py b/beetsplug/badfiles.py index 0be08bae5f..fdfbf204a1 100644 --- a/beetsplug/badfiles.py +++ b/beetsplug/badfiles.py @@ -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): @@ -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))) diff --git a/docs/changelog.rst b/docs/changelog.rst index 8e02c974ec..f311571d58 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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