{"record":{"id":"258443a76fbac634","repo":"Mintplex-Labs/anything-llm","slug":"impossible-to-retrieve-youtube-video-id","errorCode":null,"errorMessage":"Impossible to retrieve Youtube video ID.","messagePattern":"Impossible to retrieve Youtube video ID\\.","errorType":"validation","errorClass":"YoutubeTranscriptError","httpStatus":null,"severity":"error","filePath":"collector/utils/extensions/YoutubeTranscript/YoutubeLoader/youtube-transcript.js","lineNumber":237,"sourceCode":"      }\n\n      const responseData = await response.json();\n      return this.#extractTranscriptFromResponse(responseData);\n    } catch (e) {\n      throw new YoutubeTranscriptError(e.message || e);\n    }\n  }\n\n  /**\n   * Extract video ID from a YouTube URL or verify an existing ID\n   * @param {string} videoId - Video URL or ID\n   * @returns {string} YouTube video ID\n   */\n  static retrieveVideoId(videoId) {\n    if (videoId.length === 11) return videoId; // already a valid ID most likely\n    const matchedId = validYoutubeVideoUrl(videoId, true);\n    if (matchedId) return matchedId;\n    throw new YoutubeTranscriptError(\n      \"Impossible to retrieve Youtube video ID.\"\n    );\n  }\n}\n\nmodule.exports = {\n  YoutubeTranscript,\n  YoutubeTranscriptError,\n};\n","sourceCodeStart":219,"sourceCodeEnd":247,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/collector/utils/extensions/YoutubeTranscript/YoutubeLoader/youtube-transcript.js#L219-L247","documentation":"Thrown by the static `YoutubeTranscript.retrieveVideoId(videoId)` when the input is neither an 11-character string nor parseable by `validYoutubeVideoUrl`. This is the entry-point guard for the transcript fetcher and mirrors error 41, but it also accepts a bare 11-char id as a fast path, so it fires only when both the length check and URL extraction fail.","triggerScenarios":"Passing an id shorter/longer than 11 chars that is also not a URL (`'abc'`, `'123456789012'`); passing a non-YouTube URL; passing a YouTube URL whose id segment failed extraction; undefined/null after the `.length` access already threw elsewhere; a playlist URL with no video id.","commonSituations":"Frontend passes the raw YouTube page URL or a `youtu.be` short link in a format the validator rejects; user submits a playlist or channel link instead of a video; whitespace or a trailing slash in the id makes the length !== 11.","solutions":["Trim the input and, if it looks like an 11-char id, pass it directly to bypass URL parsing.","Run `validYoutubeVideoUrl(input, true)` first and reject with a UI-friendly message if it returns null.","For URLs, prefer extracting the id with `YoutubeLoader.getVideoID(url)` and passing the bare id.","Guard against playlist/channel URLs upstream and ask the user for a single video URL."],"exampleFix":"// before\nconst transcript = await YoutubeTranscript.fetchTranscript(rawInput);\n\n// after\nconst id = YoutubeTranscript.retrieveVideoId(String(rawInput).trim());\nif (!id) throw new Error('Please provide a YouTube video URL or 11-character id');\nconst transcript = await YoutubeTranscript.fetchTranscript(id);","handlingStrategy":"validation","validationCode":"function resolveVideoId(input) {\n  const v = String(input || '').trim();\n  if (/^[A-Za-z0-9_-]{11}$/.test(v)) return v;\n  const id = validYoutubeVideoUrl(v, true);\n  if (id) return id;\n  throw new Error('Provide a YouTube video URL or an 11-character id');\n}","typeGuard":"function isYoutubeIdOrUrl(v) {\n  const s = String(v || '').trim();\n  return /^[A-Za-z0-9_-]{11}$/.test(s) || !!validYoutubeVideoUrl(s, true);\n}","tryCatchPattern":"try {\n  const id = YoutubeTranscript.retrieveVideoId(input);\n} catch (e) {\n  if (/Impossible to retrieve Youtube video ID/i.test(e.message)) {\n    return { error: 'Please provide a valid YouTube video URL or id.' };\n  }\n  throw e;\n}","preventionTips":["Accept bare 11-char ids directly to bypass URL parsing.","Strip whitespace and reject playlist/channel URLs upstream.","Run the id through the same validYoutubeVideoUrl validator the library uses."],"tags":["youtube","validation","input-validation"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}