web: a form's own failure wording shows for an unknown error; drop the unused audio loader seam (#8300)
release / go (push) Successful in 1m41s
release / integration (push) Successful in 2m21s
release / web (push) Successful in 1m1s
release / govulncheck (push) Successful in 18s
release / android (push) Successful in 5m13s
release / Build signed APK (push) Successful in 7m0s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 37s
release / Verify release artifacts (tag releases only) (push) Skipped

errMessage took a fallback but looked codes up with copyForCode, which never
returns nothing, so a settings card's "Couldn't save proxy depth." was
never seen: an unknown code read "Something went wrong." It now uses
knownCopy, as the register page already did, and copyForCode is gone.

audioLoader let a desktop shell swap the stream URL for its own cache. No
such shell exists and nothing called setAudioLoader, so the player reads
the track's stream_url directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 17:14:09 -05:00
co-authored by Claude Opus 5.5
parent 877bb7e9c4
commit e11e2f1649
6 changed files with 16 additions and 106 deletions
-5
View File
@@ -7,8 +7,3 @@ export const ERROR_COPY: Readonly<Record<string, string>> = errorCopyJson;
export function knownCopy(code: string | null | undefined): string | undefined { export function knownCopy(code: string | null | undefined): string | undefined {
return code && code !== 'unknown' ? ERROR_COPY[code] : undefined; return code && code !== 'unknown' ? ERROR_COPY[code] : undefined;
} }
export function copyForCode(code: string | null | undefined): string {
if (!code) return ERROR_COPY.unknown ?? 'Something went wrong.';
return ERROR_COPY[code] ?? ERROR_COPY.unknown ?? 'Something went wrong.';
}
+8
View File
@@ -20,6 +20,14 @@ describe('errMessage', () => {
expect(errMessage({ code: 'track_not_found' })).toBe(ERROR_COPY.track_not_found); expect(errMessage({ code: 'track_not_found' })).toBe(ERROR_COPY.track_not_found);
expect(errMessage({ code: 'definitely_not_a_real_code_xyz' })).toBe(ERROR_COPY.unknown); expect(errMessage({ code: 'definitely_not_a_real_code_xyz' })).toBe(ERROR_COPY.unknown);
}); });
// A form names what failed in its own words when the server's code has no
// copy of its own; a known code still says the specific thing.
test("an unknown code reads as the caller's own wording", () => {
expect(errMessage({ code: 'definitely_not_a_real_code_xyz' }, "Couldn't save.")).toBe("Couldn't save.");
expect(errMessage(null, "Couldn't save.")).toBe("Couldn't save.");
expect(errMessage({ code: 'track_not_found' }, "Couldn't save.")).toBe(ERROR_COPY.track_not_found);
});
}); });
describe('errMessage detail codes', () => { describe('errMessage detail codes', () => {
+6 -5
View File
@@ -1,4 +1,4 @@
import { copyForCode } from './error-copy'; import { knownCopy } from './error-copy';
import detailCodesJson from '../styles/error-detail-codes.json'; import detailCodesJson from '../styles/error-detail-codes.json';
/** /**
@@ -23,14 +23,15 @@ export function errCode(err: unknown): string {
const DETAIL_CODES: ReadonlySet<string> = new Set(detailCodesJson); const DETAIL_CODES: ReadonlySet<string> = new Set(detailCodesJson);
/** /**
* Returns user-facing copy for an unknown error value. Looks up the * Returns user-facing copy for an unknown error value: the copy for its
* error's code in the error-copy map; falls back to the supplied * code when the code is known, and otherwise the caller's own wording,
* fallback (default: "Something went wrong.") when the code is unknown. * such as a form's "Couldn't save the public address." (default:
* "Something went wrong.").
* For a DETAIL_CODES code, the server's message is appended. * For a DETAIL_CODES code, the server's message is appended.
*/ */
export function errMessage(err: unknown, fallback = 'Something went wrong.'): string { export function errMessage(err: unknown, fallback = 'Something went wrong.'): string {
const code = errCode(err); const code = errCode(err);
const copy = copyForCode(code) ?? fallback; const copy = knownCopy(code) ?? fallback;
if (!DETAIL_CODES.has(code)) return copy; if (!DETAIL_CODES.has(code)) return copy;
const detail = (err as { message?: unknown })?.message; const detail = (err as { message?: unknown })?.message;
return typeof detail === 'string' && detail.trim() !== '' ? `${copy} ${detail}` : copy; return typeof detail === 'string' && detail.trim() !== '' ? `${copy} ${detail}` : copy;
-52
View File
@@ -1,52 +0,0 @@
import { afterEach, describe, expect, test, vi } from 'vitest';
import type { TrackRef } from '#lib/api/types.js';
import { audioLoader, setAudioLoader, __resetAudioLoader } from './audioLoader';
const sampleTrack: TrackRef = {
id: 't1',
title: 'Sample',
album_id: 'a1',
album_title: 'Album',
artist_id: 'ar1',
artist_name: 'Artist',
duration_sec: 180,
stream_url: '/api/tracks/t1/stream'
};
afterEach(() => {
__resetAudioLoader();
});
describe('audioLoader', () => {
test('default resolve returns the track stream_url', () => {
expect(audioLoader.resolve(sampleTrack)).toBe('/api/tracks/t1/stream');
});
test('default prefetch is a no-op (does not throw)', () => {
expect(() => audioLoader.prefetch?.(sampleTrack)).not.toThrow();
});
test('setAudioLoader swaps the resolver', () => {
setAudioLoader({
resolve: (t) => `blob:cached-${t.id}`
});
expect(audioLoader.resolve(sampleTrack)).toBe('blob:cached-t1');
});
test('setAudioLoader swaps the prefetch hook', () => {
const spy = vi.fn();
setAudioLoader({
resolve: (t) => t.stream_url,
prefetch: spy
});
audioLoader.prefetch?.(sampleTrack);
expect(spy).toHaveBeenCalledWith(sampleTrack);
});
test('__resetAudioLoader restores the default', () => {
setAudioLoader({ resolve: () => 'blob:swapped' });
expect(audioLoader.resolve(sampleTrack)).toBe('blob:swapped');
__resetAudioLoader();
expect(audioLoader.resolve(sampleTrack)).toBe('/api/tracks/t1/stream');
});
});
-40
View File
@@ -1,40 +0,0 @@
// Audio loader seam: returns the server-relative stream URL directly. A
// native shell can swap the loader to return blob URLs backed by its own
// cache, without touching the player UI.
//
// Two operations:
// - resolve(track) — returns the URL the <audio> element should src.
// - prefetch(track) — hint that a track will be needed soon. Default
// no-op (the browser handles it via the prefetch <audio> element);
// a native shell can warm its cache here.
import type { TrackRef } from '#lib/api/types.js';
export type AudioLoader = {
resolve: (track: TrackRef) => string;
prefetch?: (track: TrackRef) => void;
};
const defaultLoader: AudioLoader = {
resolve: (track) => track.stream_url
};
let _current: AudioLoader = defaultLoader;
export const audioLoader: AudioLoader = {
resolve: (track) => _current.resolve(track),
prefetch: (track) => _current.prefetch?.(track)
};
/**
* Replace the active loader. Call once at startup from the Tauri shell;
* web shell uses the default and never calls this.
*/
export function setAudioLoader(loader: AudioLoader): void {
_current = loader;
}
/** Test-only: restore the default loader between tests. */
export function __resetAudioLoader(): void {
_current = defaultLoader;
}
+2 -4
View File
@@ -26,7 +26,6 @@
import { useServerEvents } from '#lib/serverEvents.svelte.js'; import { useServerEvents } from '#lib/serverEvents.svelte.js';
import { useGlobalShortcuts } from '#lib/player/shortcuts.svelte.js'; import { useGlobalShortcuts } from '#lib/player/shortcuts.svelte.js';
import { applyMetaThemeColor } from '#lib/theme/applyMetaThemeColor.svelte.js'; import { applyMetaThemeColor } from '#lib/theme/applyMetaThemeColor.svelte.js';
import { audioLoader } from '#lib/player/audioLoader.js';
import { attachStallRetry } from '#lib/player/stallRetry.js'; import { attachStallRetry } from '#lib/player/stallRetry.js';
import { import {
applyGain, applyGain,
@@ -67,7 +66,7 @@
$effect(() => { $effect(() => {
if (!audioEl) return; if (!audioEl) return;
const cur = player.current; const cur = player.current;
const src = cur ? audioLoader.resolve(cur) : null; const src = cur ? cur.stream_url : null;
if (src) { if (src) {
const absolute = new URL(src, window.location.origin).href; const absolute = new URL(src, window.location.origin).href;
if (audioEl.src !== absolute) audioEl.src = src; if (audioEl.src !== absolute) audioEl.src = src;
@@ -87,10 +86,9 @@
const next = player.queue[player.index + 1]; const next = player.queue[player.index + 1];
const ratio = player.duration > 0 ? player.position / player.duration : 0; const ratio = player.duration > 0 ? player.position / player.duration : 0;
if (next && ratio >= 0.5) { if (next && ratio >= 0.5) {
const nextSrc = audioLoader.resolve(next); const nextSrc = next.stream_url;
if (prefetchEl.src !== new URL(nextSrc, window.location.origin).href) { if (prefetchEl.src !== new URL(nextSrc, window.location.origin).href) {
prefetchEl.src = nextSrc; prefetchEl.src = nextSrc;
audioLoader.prefetch?.(next);
} }
} else if (!next && prefetchEl.src) { } else if (!next && prefetchEl.src) {
prefetchEl.removeAttribute('src'); prefetchEl.removeAttribute('src');