Repository navigation
Player: click a playback error to see what happened and copy it #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
24c72e0
Player core: keep the details of a playback failure
githubesson d9c3554
Player: click a playback error to see what happened and copy it
githubesson 3ed54e1
Playback error details: review fixes
githubesson eeb027e
Playback error details: second review fixes
githubesson bf9e373
Playback error details: third review fixes
githubesson d8c77af
Playback error details: fourth review fixes
githubesson abf50aa
Playback error details: fifth review fixes
githubesson 3318f32
Playback error details: CodeRabbit review fixes
githubesson d126aa0
Playback error details: focus lands on Copy details
githubesson de8d3ee
Playback error details: the lines describe the dialog
githubesson 86cb68a
Playback error details: second CodeRabbit review fixes
githubesson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import type { TrackListItem } from "../api"; | ||
| import { displayText } from "../format"; | ||
| import type { PlaybackError } from "./player-core"; | ||
|
|
||
| /** One labelled line of a playback failure's details. */ | ||
| export interface PlaybackErrorLine { | ||
| label: string; | ||
| value: string; | ||
| } | ||
|
|
||
| /** | ||
| * A playback failure's details as labelled lines, in the order they're shown | ||
| * and copied. `track` is the failed track, while it's still loaded. | ||
| */ | ||
| export function playbackErrorLines( | ||
| error: PlaybackError, | ||
| track: TrackListItem | null, | ||
| ): PlaybackErrorLine[] { | ||
| const { at, source, player, server } = error.details; | ||
| const lines: PlaybackErrorLine[] = [{ label: "Error", value: error.message }]; | ||
| if (track?.id === error.trackId) { | ||
| const artist = displayText(track.artist); | ||
| const title = displayText(track.title, "Untitled"); | ||
| lines.push({ label: "Track", value: artist ? `${title} — ${artist}` : title }); | ||
| } | ||
| lines.push( | ||
| { label: "Track ID", value: error.trackId }, | ||
| { label: "Source", value: source }, | ||
| { label: "Player", value: player ?? "Gave no reason" }, | ||
| { | ||
| label: "Server", | ||
| value: server === undefined ? "Asking…" : (server ?? "Not asked: a downloaded copy"), | ||
| }, | ||
| { label: "Time", value: new Date(at).toISOString() }, | ||
| ); | ||
| return lines; | ||
| } | ||
|
|
||
| /** The lines as plain text, to copy into a bug report. */ | ||
| export function playbackErrorText(lines: PlaybackErrorLine[]): string { | ||
| return lines.map(({ label, value }) => `${label}: ${value}`).join("\n"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import type { TrackListItem } from "../src/api"; | ||
| import { playbackErrorLines, playbackErrorText } from "../src/player/playback-error"; | ||
| import type { PlaybackError } from "../src/player/player-core"; | ||
|
|
||
| const track: TrackListItem = { | ||
| id: "tidal:1", | ||
| title: "Thrills (v2.2)", | ||
| artist: "Someone", | ||
| duration_ms: 180_000, | ||
| }; | ||
|
|
||
| const failure = (details: Partial<PlaybackError["details"]> = {}): PlaybackError => ({ | ||
| trackId: "tidal:1", | ||
| message: "Couldn't play this track.", | ||
| details: { | ||
| at: Date.UTC(2026, 9, 29, 12, 0, 0), | ||
| source: "/api/tracks/tidal%3A1/stream", | ||
| player: "hls.js manifestLoadError: A network error (status 502) occurred while loading manifest", | ||
| server: "HTTP 502 · TIDAL refused to stream this track", | ||
| ...details, | ||
| }, | ||
| }); | ||
|
|
||
| describe("playbackErrorLines", () => { | ||
| it("lists what happened, in order", () => { | ||
| expect(playbackErrorText(playbackErrorLines(failure(), track))).toBe( | ||
| [ | ||
| "Error: Couldn't play this track.", | ||
| "Track: Thrills (v2.2) — Someone", | ||
| "Track ID: tidal:1", | ||
| "Source: /api/tracks/tidal%3A1/stream", | ||
| "Player: hls.js manifestLoadError: A network error (status 502) occurred while loading manifest", | ||
| "Server: HTTP 502 · TIDAL refused to stream this track", | ||
| "Time: 2026-10-29T12:00:00.000Z", | ||
| ].join("\n"), | ||
| ); | ||
| }); | ||
|
|
||
| it("says when nobody gave a reason, or the server wasn't asked", () => { | ||
| const lines = playbackErrorLines(failure({ player: null, server: null }), track); | ||
| expect(lines).toContainEqual({ label: "Player", value: "Gave no reason" }); | ||
| expect(lines).toContainEqual({ label: "Server", value: "Not asked: a downloaded copy" }); | ||
| }); | ||
|
|
||
| it("says the server is still being asked", () => { | ||
| const lines = playbackErrorLines(failure({ server: undefined }), track); | ||
| expect(lines).toContainEqual({ label: "Server", value: "Asking…" }); | ||
| }); | ||
|
|
||
| it("leaves the track out once another one is loaded", () => { | ||
| const lines = playbackErrorLines(failure(), { ...track, id: "tidal:2" }); | ||
| expect(lines.map((line) => line.label)).not.toContain("Track"); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.