From e11e2f16495dd93ce60b93d171dab66f21ec880e Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 2 Dec 2026 17:14:09 -0500 Subject: [PATCH] web: a form's own failure wording shows for an unknown error; drop the unused audio loader seam (#8300) 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 --- web/src/lib/api/error-copy.ts | 5 --- web/src/lib/api/errors.test.ts | 8 ++++ web/src/lib/api/errors.ts | 11 +++--- web/src/lib/player/audioLoader.test.ts | 52 -------------------------- web/src/lib/player/audioLoader.ts | 40 -------------------- web/src/routes/+layout.svelte | 6 +-- 6 files changed, 16 insertions(+), 106 deletions(-) delete mode 100644 web/src/lib/player/audioLoader.test.ts delete mode 100644 web/src/lib/player/audioLoader.ts diff --git a/web/src/lib/api/error-copy.ts b/web/src/lib/api/error-copy.ts index 0e6bd122..363a2d96 100644 --- a/web/src/lib/api/error-copy.ts +++ b/web/src/lib/api/error-copy.ts @@ -7,8 +7,3 @@ export const ERROR_COPY: Readonly> = errorCopyJson; export function knownCopy(code: string | null | undefined): string | 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.'; -} diff --git a/web/src/lib/api/errors.test.ts b/web/src/lib/api/errors.test.ts index 68333bfc..74e83ae9 100644 --- a/web/src/lib/api/errors.test.ts +++ b/web/src/lib/api/errors.test.ts @@ -20,6 +20,14 @@ describe('errMessage', () => { 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); }); + + // 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', () => { diff --git a/web/src/lib/api/errors.ts b/web/src/lib/api/errors.ts index 97e2985b..e2e4b277 100644 --- a/web/src/lib/api/errors.ts +++ b/web/src/lib/api/errors.ts @@ -1,4 +1,4 @@ -import { copyForCode } from './error-copy'; +import { knownCopy } from './error-copy'; import detailCodesJson from '../styles/error-detail-codes.json'; /** @@ -23,14 +23,15 @@ export function errCode(err: unknown): string { const DETAIL_CODES: ReadonlySet = new Set(detailCodesJson); /** - * Returns user-facing copy for an unknown error value. Looks up the - * error's code in the error-copy map; falls back to the supplied - * fallback (default: "Something went wrong.") when the code is unknown. + * Returns user-facing copy for an unknown error value: the copy for its + * code when the code is known, and otherwise the caller's own wording, + * 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. */ export function errMessage(err: unknown, fallback = 'Something went wrong.'): string { const code = errCode(err); - const copy = copyForCode(code) ?? fallback; + const copy = knownCopy(code) ?? fallback; if (!DETAIL_CODES.has(code)) return copy; const detail = (err as { message?: unknown })?.message; return typeof detail === 'string' && detail.trim() !== '' ? `${copy} ${detail}` : copy; diff --git a/web/src/lib/player/audioLoader.test.ts b/web/src/lib/player/audioLoader.test.ts deleted file mode 100644 index 7076ad82..00000000 --- a/web/src/lib/player/audioLoader.test.ts +++ /dev/null @@ -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'); - }); -}); diff --git a/web/src/lib/player/audioLoader.ts b/web/src/lib/player/audioLoader.ts deleted file mode 100644 index aaaf2739..00000000 --- a/web/src/lib/player/audioLoader.ts +++ /dev/null @@ -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