Skip to content

Commit

Permalink
Show fetch errors to the user
Browse files Browse the repository at this point in the history
  • Loading branch information
Douile committed Sep 18, 2023
1 parent d2a63c9 commit f895cb4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions friends_queue/friends_queue.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ body > * {
border-color: #fff transparent #fff transparent;
animation: lds-dual-ring 1.2s linear infinite;
}
.queue-item.error::before {
content: "⚠";
color: #f00;
font-size: large;
}
.queue-item.error {
border: 1px solid #f00;
}
@keyframes lds-dual-ring {
from {
transform: rotate(0deg);
Expand Down
10 changes: 10 additions & 0 deletions friends_queue/friends_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,16 @@ def generate_page(wfile, player: mpv.MPV, queue: VideoQueue, text: str):
"utf-8",
)
)
# Recent errors
for error in queue.recent_errors():
wfile.write(
bytes(
'<div class="queue-item error">{}</div>'.format(
html.escape(str(error))
),
"utf-8",
)
)
wfile.write(b"</form>")
wfile.write(
bytes(
Expand Down
11 changes: 10 additions & 1 deletion friends_queue/video_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(
self._ytdl = ytdl
self._thumbs = thumbnails
self._active: list[FetchVideoThread] = []
self._errors: list[Exception] = []

def append(self, item: VideoQueueItem):
"""Append a new video item to queue and add to mpv playlist"""
Expand Down Expand Up @@ -106,7 +107,15 @@ def active_fetches(self) -> Sequence[str]:
):
yield thread.url()
else:
self._active.pop(i)
thread = self._active.pop(i)
error = thread.get_error()
if error is not None:
self._errors.append(error)

def recent_errors(self) -> Sequence[Exception]:
"""Get recent fetch exceptions"""
while len(self._errors) > 0:
yield self._errors.pop()


@dataclass
Expand Down

0 comments on commit f895cb4

Please sign in to comment.