{"record":{"id":"70e1730a4eb7885d","repo":"bilibili/flv.js","slug":"mediadatasource-must-be-an-javascript-object","errorCode":null,"errorMessage":"MediaDataSource must be an javascript object!","messagePattern":"MediaDataSource must be an javascript object!","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/flv.js","lineNumber":39,"sourceCode":"import {BaseLoader, LoaderStatus, LoaderErrors} from './io/loader.js';\nimport FlvPlayer from './player/flv-player.js';\nimport NativePlayer from './player/native-player.js';\nimport PlayerEvents from './player/player-events.js';\nimport {ErrorTypes, ErrorDetails} from './player/player-errors.js';\nimport LoggingControl from './utils/logging-control.js';\nimport {InvalidArgumentException} from './utils/exception.js';\n\n// here are all the interfaces\n\n// install polyfills\nPolyfill.install();\n\n\n// factory method\nfunction createPlayer(mediaDataSource, optionalConfig) {\n    let mds = mediaDataSource;\n    if (mds == null || typeof mds !== 'object') {\n        throw new InvalidArgumentException('MediaDataSource must be an javascript object!');\n    }\n\n    if (!mds.hasOwnProperty('type')) {\n        throw new InvalidArgumentException('MediaDataSource must has type field to indicate video file type!');\n    }\n\n    switch (mds.type) {\n        case 'flv':\n            return new FlvPlayer(mds, optionalConfig);\n        default:\n            return new NativePlayer(mds, optionalConfig);\n    }\n}\n\n\n// feature detection\nfunction isSupported() {\n    return Features.supportMSEH264Playback();","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/bilibili/flv.js/blob/42343088f22619cf014a057b3878fe3d320016a6/src/flv.js#L21-L57","documentation":"createPlayer(mediaDataSource, optionalConfig) validates that mediaDataSource is a non-null JavaScript object before inspecting it. Passing null, undefined, a string, or a number cannot yield a usable player configuration, so an InvalidArgumentException is thrown immediately. It is a fail-fast input validation error.","triggerScenarios":"Calling createPlayer(null), createPlayer(undefined), createPlayer('https://example.com/video.flv') (a URL string instead of an object), or the variable holding the config being unfilled due to a failed fetch/parse.","commonSituations":"Passing a plain URL string instead of {type:'flv', url:...}; async config not yet loaded when createPlayer runs; JSON.parse failure silently yielding null; typos assigning the config to a different variable.","solutions":["Pass a proper object: createPlayer({type:'flv', isLive:true, url:'...'})","If the config loads asynchronously, only call createPlayer after it resolves (or in a ready/effect callback)","Log/inspect the value right before the call to confirm it is an object"],"exampleFix":"// before\ncreatePlayer('https://example.com/video.flv', config); // throws\n// after\ncreatePlayer({type: 'flv', isLive: true, url: 'https://example.com/video.flv'}, config);","handlingStrategy":"type-guard","validationCode":"if (mediaDataSource == null || typeof mediaDataSource !== 'object') {\n  throw new TypeError('mediaDataSource must be a non-null object');\n}","typeGuard":"function isMediaDataSource(v) {\n  return typeof v === 'object' && v !== null && !Array.isArray(v) && typeof v.type === 'string';\n}","tryCatchPattern":"try {\n  const player = createPlayer(mediaDataSource, config);\n} catch (e) {\n  if (e.name === 'InvalidArgumentException') {\n    console.error('Bad mediaDataSource, got:', typeof mediaDataSource, mediaDataSource);\n  } else { throw e; }\n}","preventionTips":["Always pass an object literal {type:'flv', url:'...'}, never a raw URL string","Await async config load before calling createPlayer","Type the config with JSDoc/TypeScript so invalid shapes fail at compile time","Log the value at the call site when debugging factory errors"],"tags":["validation","arguments","configuration","factory"],"backgroundTag":"invalid-argument-value","analyzedSha":"42343088f22619cf014a057b3878fe3d320016a6","analyzedAt":"2026-09-01T00:27:28.147Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}