{"record":{"id":"ec33ad209ab2e413","repo":"bilibili/flv.js","slug":"url-must-be-a-non-empty-string","errorCode":null,"errorMessage":"Url must be a non-empty string!","messagePattern":"Url must be a non-empty string!","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/io/io-controller.js","lineNumber":354,"sourceCode":"        this._loader.destroy();\n        this._loader = null;\n\n        let requestRange = {from: bytes, to: -1};\n        this._currentRange = {from: requestRange.from, to: -1};\n\n        this._speedSampler.reset();\n        this._stashSize = this._stashInitialSize;\n        this._createLoader();\n        this._loader.open(this._dataSource, requestRange);\n\n        if (this._onSeeked) {\n            this._onSeeked();\n        }\n    }\n\n    updateUrl(url) {\n        if (!url || typeof url !== 'string' || url.length === 0) {\n            throw new InvalidArgumentException('Url must be a non-empty string!');\n        }\n\n        this._dataSource.url = url;\n\n        // TODO: replace with new url\n    }\n\n    _expandBuffer(expectedBytes) {\n        let bufferNewSize = this._stashSize;\n        while (bufferNewSize + 1024 * 1024 * 1 < expectedBytes) {\n            bufferNewSize *= 2;\n        }\n\n        bufferNewSize += 1024 * 1024 * 1;  // bufferSize = stashSize + 1MB\n        if (bufferNewSize === this._bufferSize) {\n            return;\n        }\n","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/bilibili/flv.js/blob/42343088f22619cf014a057b3878fe3d320016a6/src/io/io-controller.js#L336-L372","documentation":"IOController.updateUrl() validates its argument before assigning it to the internal data source URL. The library throws InvalidArgumentException when the url is falsy, not a string, or an empty string, because a subsequent load with an invalid URL could never succeed. It is a defensive API-contract check for the caller.","triggerScenarios":"Calling ioController.updateUrl(undefined), updateUrl(null), updateUrl(''), or updateUrl(123) / any non-string value. Only IOController.updateUrl(src/io/io-controller.js:354) throws it.","commonSituations":"Passing a variable that was never populated (e.g. a URL fetched asynchronously that came back empty), reading a config field that is undefined, or accidentally passing a URL object instead of a string.","solutions":["Pass a non-empty string to updateUrl, e.g. updateUrl(String(newUrl)).","Coerce or validate the value first: if (typeof newUrl === 'string' && newUrl.length > 0) controller.updateUrl(newUrl).","Check where the URL originates (config, API response) and fix the empty/undefined source."],"exampleFix":"// before\ncontroller.updateUrl(urlFromServer);\n// after\nif (typeof urlFromServer === 'string' && urlFromServer.length > 0) {\n    controller.updateUrl(urlFromServer);\n}","handlingStrategy":"validation","validationCode":"function canUpdateUrl(url) {\n    return typeof url === 'string' && url.length > 0;\n}\nif (canUpdateUrl(newUrl)) ioController.updateUrl(newUrl);","typeGuard":"function isNonEmptyString(v) {\n    return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":"try {\n    ioController.updateUrl(candidate);\n} catch (e) {\n    if (e.name === 'InvalidArgumentException') console.warn('Invalid URL skipped:', candidate);\n    else throw e;\n}","preventionTips":["Validate URL sources (API/config) at ingestion time before they reach the player layer.","Coerce URL-like objects with String() only after confirming they are string-like.","Add a unit test asserting updateUrl rejects empty/undefined values."],"tags":["argument-validation","url","api-misuse"],"backgroundTag":"invalid-argument","analyzedSha":"42343088f22619cf014a057b3878fe3d320016a6","analyzedAt":"2026-09-01T00:27:28.147Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}