Mic92 / python-mpd2

Python library which provides a client interface for the Music Player Daemon.
GNU Lesser General Public License v3.0
352 stars 119 forks source link

Parse failure responses in CommandError exception #160

Closed mweinelt closed 3 years ago

mweinelt commented 3 years ago

This allows for improved error handling based on error numbers, offsets in a command list, command and ultimately also hands you the literal error message.

The whole story is, that a home-assistant user came forward complainig about the noise from albumart commands that returned

[50@0] {albumart} No file exists

for every song, that didn't have any. There is currently no clean way to ignore specific errors, but to rely on string matching. Instead of everyone doing that for themselves I believe a simple pattern like this might be useful.

Mic92 commented 3 years ago

Could you add this to https://github.com/Mic92/python-mpd2/blob/master/examples/errorhandling.py as well?

mweinelt commented 3 years ago

On Mon, Jan 18, 2021 at 01:12:59AM -0800, Jörg Thalheim wrote:

Could you add this to https://github.com/Mic92/python-mpd2/blob/master/examples/errorhandling.py as well?

Sure thing.

How close to we want to stick to the protocols nomenclature? Specifically:

error: numeric value of one of the ACK_ERROR constants defined in src/protocol/Ack.hxx.

command_listNum: offset of the command that caused the error in a Command List. An error will always cause a command list to terminate at the command that causes the error.

current_command: name of the command, in a Command List, that was executing when the error occurred.

message_text: some (hopefully) informative text that describes the nature of the error.

https://www.musicpd.org/doc/html/protocol.html#failure-responses

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/Mic92/python-mpd2/pull/160#issuecomment-762104596

mweinelt commented 3 years ago

Oh and I think we could include the error definitions, to make the resulting code more readable. Sadly enums are 3.4+ only.

Mic92 commented 3 years ago

Oh and I think we could include the error definitions, to make the resulting code more readable. Sadly enums are 3.4+ only.

python-mpd2 is python3.6+.

mweinelt commented 3 years ago

Oh and I think we could include the error definitions, to make the resulting code more readable. Sadly enums are 3.4+ only.

python-mpd2 is python3.6+.

Ah right. Would yo mind if i squash them into __init__.py then? Like from mpd import errors, where errors would be the enum.

Mic92 commented 3 years ago

Oh and I think we could include the error definitions, to make the resulting code more readable. Sadly enums are 3.4+ only.

python-mpd2 is python3.6+.

Ah right. Would yo mind if i squash them into __init__.py then? Like from mpd import errors, where errors would be the enum.

go ahead.

patagonaa commented 3 years ago

Is there anything missing or can this be merged and released?

Mic92 commented 3 years ago

Looks good to me. @mweinelt can merge this if he thinks it's ready.

patagonaa commented 3 years ago

ping @mweinelt