{"record":{"id":"41dc5e1f30174d27","repo":"remotion-dev/remotion","slug":"the-associated-playlist-json-stringify-streams","errorCode":null,"errorMessage":"The associated playlist ${JSON.stringify(streams)} cannot be selected because it was not in the list of selectable playlists","messagePattern":"The associated playlist (.+?) cannot be selected because it was not in the list of selectable playlists","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/m3u/select-stream.ts","lineNumber":44,"sourceCode":"\tskipAudioTracks: boolean;\n}): Promise<M3uAssociatedPlaylist[]> => {\n\tif (playlists.length < 1) {\n\t\treturn Promise.resolve([]);\n\t}\n\n\tconst streams = await fn({associatedPlaylists: playlists});\n\tif (!Array.isArray(streams)) {\n\t\tthrow new Error('Expected an array of associated playlists');\n\t}\n\n\tconst selectedStreams: M3uAssociatedPlaylist[] = [];\n\tfor (const stream of streams) {\n\t\tif (stream.isAudio && skipAudioTracks) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (!playlists.find((playlist) => playlist.src === stream.src)) {\n\t\t\tthrow new Error(\n\t\t\t\t`The associated playlist ${JSON.stringify(streams)} cannot be selected because it was not in the list of selectable playlists`,\n\t\t\t);\n\t\t}\n\n\t\tselectedStreams.push(stream);\n\t}\n\n\treturn selectedStreams;\n};\n\nexport const defaultSelectM3uAssociatedPlaylists: SelectM3uAssociatedPlaylistsFn =\n\t({associatedPlaylists}) => {\n\t\tif (associatedPlaylists.length === 1) {\n\t\t\treturn associatedPlaylists;\n\t\t}\n\n\t\treturn associatedPlaylists.filter((playlist) => playlist.default);\n\t};","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/m3u/select-stream.ts#L26-L62","documentation":"Thrown by `selectAssociatedPlaylists` when the custom `selectM3uAssociatedPlaylists` callback returns a playlist whose `src` property does not match any playlist in the original selectable list. The callback may only return a subset of the playlists it was given — it cannot invent new playlists or modify their `src` values.","triggerScenarios":"A custom `selectM3uAssociatedPlaylists` callback that constructs and returns a `M3uAssociatedPlaylist` object with a `src` value not present in the `associatedPlaylists` array it received. The guard iterates each returned stream and checks `playlists.find((playlist) => playlist.src === stream.src)`.","commonSituations":"A callback that returns a modified copy of a playlist with a different `src`. A callback that returns playlists from a different/cached stream manifest. Returning hardcoded playlist objects instead of selecting from the offered list. Merging playlists from multiple manifests.","solutions":["Return only playlist objects that came directly from the `associatedPlaylists` array passed to your callback.","Select by reference or by matching `src` from the input: `return associatedPlaylists.filter(condition)`.","If you need a different playlist, filter on properties (e.g., `.default`, `.language`) rather than constructing new objects.","Do not mutate the `src` field of returned playlist objects."],"exampleFix":"// before\nselectM3uAssociatedPlaylists: ({associatedPlaylists}) => {\n  return [{...associatedPlaylists[0], src: 'https://my-cdn.com/audio.m3u8'}];\n}\n\n// after\nselectM3uAssociatedPlaylists: ({associatedPlaylists}) => {\n  return associatedPlaylists.filter(p => p.default);\n}","handlingStrategy":"validation","validationCode":"// Validate that returned playlists are a subset of the input\nimport type {SelectM3uAssociatedPlaylistsFn} from '@remotion/media-parser';\n\nconst safeSelect: SelectM3uAssociatedPlaylistsFn = ({associatedPlaylists}) => {\n  const validSrcs = new Set(associatedPlaylists.map((p) => p.src));\n  const selected = myCustomFilter(associatedPlaylists);\n  // Ensure every returned item has a src from the original list\n  for (const s of selected) {\n    if (!validSrcs.has(s.src)) {\n      throw new Error(`Returned playlist src not in selectable list: ${s.src}`);\n    }\n  }\n  return selected;\n};","typeGuard":null,"tryCatchPattern":"try {\n  await parseMedia({src, selectM3uAssociatedPlaylists: myFn});\n} catch (e) {\n  if (e instanceof Error && e.message.includes('cannot be selected because it was not in the list')) {\n    console.error('Your callback returned a playlist not from the offered list.');\n  }\n  throw e;\n}","preventionTips":["Return only playlist objects from the associatedPlaylists array you received.","Never modify the src field of returned playlists.","Use .filter() on the input array instead of constructing new objects.","Do not merge playlists from different manifests in your callback."],"tags":["hls","m3u8","callback-contract","select-playlist","validation"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}