diff --git a/docs/changelog.rst b/docs/changelog.rst index b0e9fa45..e3b4826f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -7,6 +7,11 @@ This changelog is used to track all major changes to Mopidy. v0.18.0 (UNRELEASED) ==================== +**MPD frontend** + +- Empty commands now return a ``ACK [5@0] {} No command given`` error instead + of ``OK``. This is consistent with the original MPD server implementation. + **Core API** - Expose :meth:`mopidy.core.Core.version` for HTTP clients to manage diff --git a/mopidy/mpd/exceptions.py b/mopidy/mpd/exceptions.py index db3212d8..07e3a421 100644 --- a/mopidy/mpd/exceptions.py +++ b/mopidy/mpd/exceptions.py @@ -62,6 +62,12 @@ class MpdUnknownCommand(MpdAckError): self.command = '' +class MpdNoCommand(MpdUnknownCommand): + def __init__(self, *args, **kwargs): + super(MpdNoCommand, self).__init__(*args, **kwargs) + self.message = 'No command given' + + class MpdNoExistError(MpdAckError): error_code = MpdAckError.ACK_ERROR_NO_EXIST diff --git a/mopidy/mpd/protocol/empty.py b/mopidy/mpd/protocol/empty.py index 9b3d6883..9cb0aa6b 100644 --- a/mopidy/mpd/protocol/empty.py +++ b/mopidy/mpd/protocol/empty.py @@ -1,9 +1,10 @@ from __future__ import unicode_literals from mopidy.mpd.protocol import handle_request +from mopidy.mpd.exceptions import MpdNoCommand @handle_request(r'[\ ]*$') def empty(context): - """The original MPD server returns ``OK`` on an empty request.""" - pass + """The original MPD server returns an error on an empty request.""" + raise MpdNoCommand diff --git a/tests/mpd/exception_test.py b/tests/mpd/exception_test.py index ae59253e..88a8cdda 100644 --- a/tests/mpd/exception_test.py +++ b/tests/mpd/exception_test.py @@ -3,8 +3,8 @@ from __future__ import unicode_literals import unittest from mopidy.mpd.exceptions import ( - MpdAckError, MpdPermissionError, MpdUnknownCommand, MpdSystemError, - MpdNotImplemented) + MpdAckError, MpdPermissionError, MpdUnknownCommand, MpdNoCommand, + MpdSystemError, MpdNotImplemented) class MpdExceptionsTest(unittest.TestCase): @@ -41,6 +41,14 @@ class MpdExceptionsTest(unittest.TestCase): e.get_mpd_ack(), 'ACK [5@0] {} unknown command "play"') + def test_mpd_no_command(self): + try: + raise MpdNoCommand + except MpdAckError as e: + self.assertEqual( + e.get_mpd_ack(), + 'ACK [5@0] {} No command given') + def test_mpd_system_error(self): try: raise MpdSystemError('foo') diff --git a/tests/mpd/protocol/connection_test.py b/tests/mpd/protocol/connection_test.py index 452a2147..34cce6a0 100644 --- a/tests/mpd/protocol/connection_test.py +++ b/tests/mpd/protocol/connection_test.py @@ -14,10 +14,10 @@ class ConnectionHandlerTest(protocol.BaseTestCase): def test_empty_request(self): self.sendRequest('') - self.assertEqualResponse('OK') + self.assertEqualResponse('ACK [5@0] {} No command given') self.sendRequest(' ') - self.assertEqualResponse('OK') + self.assertEqualResponse('ACK [5@0] {} No command given') def test_kill(self): self.sendRequest('kill')