Hi!
Ive realized that the error handling of commands is a bit limited. I explain.
So for example if we try to do client.sticker_get("song", uri, tag) and the particular sticker doesnt exist in that uri we get a:
CommandError: [50@0] {sticker} no such sticker
But if the sticker database isnt active we get
CommandError: [5@0] {sticker} sticker database is disabled
Same error (a very clear different accompany text tho, nice) for two arguebly very different things
In a example code:
try:
played=int(client.sticker_get("song", song["file"], "played"))
exceptCommandError:
played=0try:
client.sticker_set("song", song["file"], "played", played+1)
exceptCommandError:
passAgainst:
try:
played=int(client.sticker_get("song", song["file"], "played"))
exceptNoStickerError:
played=0exceptStickerDBError:
passelse:
client.sticker_set("song", song["file"], "played", played+1)Dont give too much importance to the example itself, its just where i realized this, given the solution it doesnt make "much" difference; but i do belive it would be better practice to have clearer errors. Havent tried but I imagine similar things might occur with other commands.
Also it could be argued that if a sticker doesnt exist it could return None instead of error. That would make the code:
# At the start of the codetry:
# A test to see that stickers db is activatedexceptStickerDBError:
# whatever# ...played=client.sticker_get("song", song["file"], "played")
ifplayedisNone:
played=0client.sticker_set("song", song["file"], "played", int(played) +1)But i gues thats more about what mpd itself wants to do, and it wouldnt be quite right to have a different behaviour here
Thanks for the amazing library! :D
Hi!
Ive realized that the error handling of commands is a bit limited. I explain.
So for example if we try to do
client.sticker_get("song", uri, tag)and the particular sticker doesnt exist in that uri we get a:But if the sticker database isnt active we get
Same error (a very clear different accompany text tho, nice) for two arguebly very different things
In a example code:
Against:
Dont give too much importance to the example itself, its just where i realized this, given the solution it doesnt make "much" difference; but i do belive it would be better practice to have clearer errors. Havent tried but I imagine similar things might occur with other commands.
Also it could be argued that if a sticker doesnt exist it could return None instead of error. That would make the code:
But i gues thats more about what mpd itself wants to do, and it wouldnt be quite right to have a different behaviour here
Thanks for the amazing library! :D