Skip to content

Commit

Permalink
Graceful invalid queue (#2391)
Browse files Browse the repository at this point in the history
* return none rather than raise an error on bad deserialize version.

* Python 3.8 compat I somehow missed.

* py 3.8 compat with proper formatting.

* now actually use the type alias.

* i am scatter brain today. :)
  • Loading branch information
itsTheFae committed Feb 14, 2024
1 parent 0b9f37b commit 1d635ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 8 additions & 4 deletions musicbot/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,11 @@ def _deserialize(

vernum: Optional[int] = raw_json.get("version", None)
if not vernum:
raise InvalidDataError("Entry data is missing version number.")
log.error("Entry data is missing version number, cannot deserialize.")
return None
if vernum != URLPlaylistEntry.SERIAL_VERSION:
raise InvalidDataError("Entry data has the wrong version number.")
log.error("Entry data has the wrong version number, cannot deserialize.")
return None

try:
info = YtdlpResponseDict(raw_json["info"])
Expand Down Expand Up @@ -720,9 +722,11 @@ def _deserialize(

vernum = raw_json.get("version", None)
if not vernum:
raise InvalidDataError("Entry data is missing version number.")
log.error("Entry data is missing version number, cannot deserialize.")
return None
if vernum != URLPlaylistEntry.SERIAL_VERSION:
raise InvalidDataError("Entry data has the wrong version number.")
log.error("Entry data has the wrong version number, cannot deserialize.")
return None

try:
info = YtdlpResponseDict(raw_json["info"])
Expand Down
8 changes: 6 additions & 2 deletions musicbot/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
from .bot import MusicBot
from .playlist import Playlist

AsyncFuture = asyncio.Future[Any]
else:
AsyncFuture = asyncio.Future

# Type alias
EntryTypes = Union[URLPlaylistEntry, StreamPlaylistEntry]

Expand Down Expand Up @@ -95,7 +99,7 @@ def __init__(
self._play_lock = asyncio.Lock()
self._current_player: Optional[VoiceClient] = None
self._current_entry: Optional[EntryTypes] = None
self._stderr_future: Optional[asyncio.Future[Any]] = None
self._stderr_future: Optional[AsyncFuture] = None

self._source: Optional[SourcePlaybackCounter] = None

Expand Down Expand Up @@ -524,7 +528,7 @@ def progress(self) -> float:
# TODO: I need to add a check if the event loop is closed?


def filter_stderr(stderr: io.BytesIO, future: asyncio.Future[Any]) -> None:
def filter_stderr(stderr: io.BytesIO, future: AsyncFuture) -> None:
"""
Consume a `stderr` bytes stream and check it for errors or warnings.
Set the given `future` with either an error found in the stream or
Expand Down

0 comments on commit 1d635ba

Please sign in to comment.