From b94c6716f7156f6d3a59497dfbc5ae53d0320718 Mon Sep 17 00:00:00 2001 From: nicoco Date: Sat, 28 Sep 2024 10:26:09 +0200 Subject: [PATCH] xep-0231: fix TypeError when BoB cannot be found Although it is not documented whether the get_bob API call can return None, the default implementation can, which raises a TypeError when the requested BoB is not available. This commit prevents such TypeError by raising a XMPPError instead. References: https://todo.sr.ht/~nicoco/slidcord/23 --- slixmpp/plugins/xep_0231/bob.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/slixmpp/plugins/xep_0231/bob.py b/slixmpp/plugins/xep_0231/bob.py index 5614b5b0..84696feb 100644 --- a/slixmpp/plugins/xep_0231/bob.py +++ b/slixmpp/plugins/xep_0231/bob.py @@ -10,6 +10,7 @@ from asyncio import Future from typing import Optional from slixmpp import JID +from slixmpp.exceptions import XMPPError from slixmpp.stanza import Iq, Message, Presence from slixmpp.xmlstream.handler import CoroutineCallback from slixmpp.xmlstream.matcher import StanzaPath @@ -139,6 +140,13 @@ class XEP_0231(BasePlugin): self.xmpp.event('bob', iq) elif iq['type'] == 'get': data = await self.api['get_bob'](iq['to'], None, iq['from'], args=cid) + + if data is None: + raise XMPPError( + "item-not-found", + f"Bits of binary '{cid}' is not available", + ) + if isinstance(data, Iq): data['id'] = iq['id'] data.send()