Local media library detail page crashes: GET /api/media-libraries/:id returns 500

#2200 · open · 0 comments

View on GitHub ↗

chrisbenincasa

## Bug `GET /api/media-libraries/:libraryId` returns 500 for every library that belongs to a **Local** media source. The web page at `/media_sources/:mediaSourceId/libraries/:libraryId` shows the error page ("Looks like something went wrong."). Server log: ``` FST_ERR_RESPONSE_SERIALIZATION: Response doesn't match the schema path: ["mediaSource", "paths"] code: too_small, minimum: 1 ``` ## Cause - `mediaSourceDB.getLibrary()` (`server/src/db/mediaSourceDB.ts:91`) loads the parent media source with `paths` and `replacePaths`, but not `libraries`. - `convertToApiMediaSource()` in `server/src/api/mediaSourceApi.ts` builds a local source's `paths` from `source.libraries`. It gets `undefined`, so `paths` becomes `[]`. - The response schema requires a non-empty array (`types/src/schemas/settingsSchemas.ts:189`, `paths: z.array(...).nonempty()`), so serialization fails. Plex, Jellyfin, and Emby libraries are not affected. Their branch of `convertToApiMediaSource` doesn't read `paths`. ## Repro 1. Add a Local media source with one folder. 2. Open **Media Sources** → the source → the library, or `curl /api/media-libraries/<libraryId>`. 3. Observe the 500 and the error page. ## Fix direction Load `libraries` in `getLibrary()`'s `mediaSource` relation, or derive local `paths` from the `paths` relation that the query already loads. Add a test for the local branch of the response. ## Found by The new e2e route sweep. The route is marked `test.fail()` in `e2e/tests/routes.ts`, so the sweep will flag it once this is fixed and the marker can be removed.

Comments