{"record":{"id":"cd4f1f0470caf0e0","repo":"Mintplex-Labs/anything-llm","slug":"invalid-video-id","errorCode":null,"errorMessage":"Invalid video id!","messagePattern":"Invalid video id!","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/utils/extensions/YoutubeTranscript/YoutubeLoader/index.js","lineNumber":16,"sourceCode":"const { validYoutubeVideoUrl } = require(\"../../../url\");\n\n/*\n * This is just a custom implementation of the Langchain JS YouTubeLoader class\n * as the dependency for YoutubeTranscript is quite fickle and its a rat race to keep it up\n * and instead of waiting for patches we can just bring this simple script in-house and at least\n * be able to patch it since its so flaky. When we have more connectors we can kill this because\n * it will be a pain to maintain over time.\n */\nclass YoutubeLoader {\n  #videoId;\n  #language;\n  #addVideoInfo;\n\n  constructor({ videoId = null, language = null, addVideoInfo = false } = {}) {\n    if (!videoId) throw new Error(\"Invalid video id!\");\n    this.#videoId = videoId;\n    this.#language = language;\n    this.#addVideoInfo = addVideoInfo;\n  }\n\n  /**\n   * Extracts the videoId from a YouTube video URL.\n   * @param url The URL of the YouTube video.\n   * @returns The videoId of the YouTube video.\n   */\n  static getVideoID(url) {\n    const videoId = validYoutubeVideoUrl(url, true);\n    if (videoId) return videoId;\n    throw new Error(\"Failed to get youtube video id from the url\");\n  }\n\n  /**\n   * Creates a new instance of the YoutubeLoader class from a YouTube video","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/collector/utils/extensions/YoutubeTranscript/YoutubeLoader/index.js#L1-L34","documentation":"Thrown by the YoutubeLoader constructor when the `videoId` argument is falsy (null, undefined, empty string, or 0). This is an in-house port of LangChain's YouTube loader; the constructor is the single gate that guarantees a downstream fetch URL can be built. It fires before any network call, so it is purely an input-contract violation, not a transient failure.","triggerScenarios":"Calling `new YoutubeLoader({})`, `new YoutubeLoader({ videoId: null })`, or `new YoutubeLoader({ videoId: '' })` directly. Also reached indirectly when `YoutubeLoader.createFromUrl(url)` succeeds in parsing but a caller passes the result's videoId as undefined, or when a code path constructs the loader from an unvalidated user-supplied field that happens to be empty.","commonSituations":"A connector or data-source ingestion job receives a YouTube record whose URL/id field is missing or was stripped by an upstream sanitizer; a refactor renames the `videoId` field but forgets one call site; tests that instantiate the loader without a fixture id.","solutions":["Validate that `videoId` is a non-empty 11-character string before constructing YoutubeLoader.","Prefer the `YoutubeLoader.createFromUrl(url, config)` static factory, which extracts and validates the id in one step.","If constructing directly, source the id only from `YoutubeLoader.getVideoID(url)` / `YoutubeTranscript.retrieveVideoId(input)` so it can never be falsy.","Wrap construction in try/catch and surface a user-facing 'invalid YouTube link' message instead of crashing the ingestion pipeline."],"exampleFix":"// before\nconst loader = new YoutubeLoader({ videoId: maybeMissing });\n\n// after\nif (!videoId || videoId.length !== 11) throw new Error('A valid 11-char YouTube video id is required');\nconst loader = new YoutubeLoader({ videoId });","handlingStrategy":"validation","validationCode":"function assertVideoId(videoId) {\n  if (typeof videoId !== 'string' || !/^[A-Za-z0-9_-]{11}$/.test(videoId)) {\n    throw new Error('A valid 11-character YouTube video id is required');\n  }\n  return videoId;\n}\n// run before constructing YoutubeLoader\nconst loader = new YoutubeLoader({ videoId: assertVideoId(maybeId) });","typeGuard":"function isValidVideoId(v) {\n  return typeof v === 'string' && /^[A-Za-z0-9_-]{11}$/.test(v);\n}","tryCatchPattern":"try {\n  const loader = new YoutubeLoader({ videoId });\n} catch (e) {\n  if (/Invalid video id/i.test(e.message)) {\n    return { error: 'Please provide a valid YouTube video link.' };\n  }\n  throw e;\n}","preventionTips":["Always obtain the videoId via YoutubeLoader.getVideoID(url) or YoutubeTranscript.retrieveVideoId(input) rather than passing raw user input.","Prefer the createFromUrl factory so extraction and construction are atomic.","Unit-test the loader with empty/null/undefined ids to lock the contract."],"tags":["youtube","validation","input-validation","constructor"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}