From 302d9e81574f32316af358ec606e7ca56b00c801 Mon Sep 17 00:00:00 2001 From: rowkav09 Date: Sat, 3 Oct 2026 23:10:35 +0100 Subject: [PATCH] Skip null entries in the Plex library sections list A null entry in Directory made testConnection throw a raw TypeError instead of a connection error. Route the list through plexRows like the other readers. The new test fails without the change and passes with it. Checked against mocked Plex responses only, not a live server. --- .../plex/src/client.sections-rows.test.ts | 21 +++++++++++++++++++ packages/plex/src/client.ts | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 packages/plex/src/client.sections-rows.test.ts diff --git a/packages/plex/src/client.sections-rows.test.ts b/packages/plex/src/client.sections-rows.test.ts new file mode 100644 index 0000000..1371f85 --- /dev/null +++ b/packages/plex/src/client.sections-rows.test.ts @@ -0,0 +1,21 @@ +import { afterEach, expect, it, vi } from 'vitest' +import { PlexClient } from './client.js' + +afterEach(() => { + vi.unstubAllGlobals() +}) + +it('skips a null entry in the library sections list instead of throwing a TypeError', async () => { + vi.stubGlobal('fetch', async (url: string) => + new Response( + JSON.stringify( + String(url).includes('/library/sections') + ? { MediaContainer: { Directory: [null, { type: 'artist', key: '1', title: 'Music' }] } } + : { MediaContainer: { machineIdentifier: 'm', version: '1' } }, + ), + ), + ) + const client = new PlexClient('http://plex.test:32400', 'tok') + const result = await client.testConnection() + expect(result.machineIdentifier).toBe('m') +}) diff --git a/packages/plex/src/client.ts b/packages/plex/src/client.ts index 23de31b..dd4b955 100644 --- a/packages/plex/src/client.ts +++ b/packages/plex/src/client.ts @@ -330,7 +330,7 @@ export class PlexClient { private async librarySections(): Promise { const payload = await this.request('/library/sections') - return (payload.MediaContainer?.Directory ?? []) + return plexRows(payload.MediaContainer?.Directory) .filter((section) => section.type === 'artist' && section.key !== undefined && section.title) .map((section) => ({ id: String(section.key),