mirror of
https://github.com/beetbox/beets.git
synced 2026-01-18 06:05:06 +01:00
bpd: error instead of crashing on extra argument
If an MPC client is expecting a command to take an argument that bpd isn't expecting (e.g. because of a difference in protocol versions) then bpd currently crashes completely. Instead, do what the real MPD does and return an error message over the protocol.
This commit is contained in:
parent
d94a5393b2
commit
0f53ae9a87
2 changed files with 14 additions and 1 deletions
|
|
@ -674,7 +674,8 @@ class Command(object):
|
|||
# Attempt to get correct command function.
|
||||
func_name = 'cmd_' + self.name
|
||||
if not hasattr(conn.server, func_name):
|
||||
raise BPDError(ERROR_UNKNOWN, u'unknown command', self.name)
|
||||
raise BPDError(ERROR_UNKNOWN,
|
||||
u'unknown command "{}"'.format(self.name))
|
||||
func = getattr(conn.server, func_name)
|
||||
|
||||
# Ensure we have permission for this command.
|
||||
|
|
@ -690,6 +691,13 @@ class Command(object):
|
|||
for data in results:
|
||||
yield conn.send(data)
|
||||
|
||||
except TypeError:
|
||||
# The client provided too many arguments.
|
||||
raise BPDError(ERROR_ARG,
|
||||
u'wrong number of arguments for "{}"'
|
||||
.format(self.name),
|
||||
self.name)
|
||||
|
||||
except BPDError as e:
|
||||
# An exposed error. Set the command name and then let
|
||||
# the Connection handle it.
|
||||
|
|
|
|||
|
|
@ -347,6 +347,11 @@ class BPDTest(BPDTestHelper):
|
|||
response = client.send_command('notacommand')
|
||||
self._assert_failed(response, bpd.ERROR_UNKNOWN)
|
||||
|
||||
def test_unexpected_argument(self):
|
||||
with self.run_bpd() as client:
|
||||
response = client.send_command('clearerror', 'extra argument')
|
||||
self._assert_failed(response, bpd.ERROR_ARG)
|
||||
|
||||
|
||||
class BPDQueryTest(BPDTestHelper):
|
||||
test_implements_query = implements({
|
||||
|
|
|
|||
Loading…
Reference in a new issue