From f284d8fad58563e98999d9630177a87fe7ea2abc Mon Sep 17 00:00:00 2001 From: Bruno Cauet Date: Sat, 31 Jan 2015 19:47:19 +0100 Subject: [PATCH] Handle shlex parse errors in query strings Provide context: offending query string. Update changelog. Fix #1290. --- beets/library.py | 5 ++++- docs/changelog.rst | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/beets/library.py b/beets/library.py index 15151e9fe..d521fc4a8 100644 --- a/beets/library.py +++ b/beets/library.py @@ -1069,7 +1069,10 @@ def parse_query_string(s, model_cls): # http://bugs.python.org/issue6988 if isinstance(s, unicode): s = s.encode('utf8') - parts = [p.decode('utf8') for p in shlex.split(s)] + try: + parts = [p.decode('utf8') for p in shlex.split(s)] + except ValueError as exc: + raise ValueError("Cannot parse {0!r} (error was: {1})".format(s, exc)) return parse_query_parts(parts, model_cls) diff --git a/docs/changelog.rst b/docs/changelog.rst index 038e6f93d..b8fc19dac 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -86,6 +86,7 @@ Fixes: like the bitrate. :bug:`1268` * The error message when MusicBrainz is not reachable on the network is now much clearer. Thanks to Tom Jaspers. :bug:`1190` :bug:`1272` +* Improve error messages when parsing query strings with shlex. :bug:`1290` For developers: