bilibili/flv.js · error · InvalidArgumentException
Url must be a non-empty string!
Error message
Url must be a non-empty string!
What it means
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.
Source
Thrown at src/io/io-controller.js:354
this._loader.destroy();
this._loader = null;
let requestRange = {from: bytes, to: -1};
this._currentRange = {from: requestRange.from, to: -1};
this._speedSampler.reset();
this._stashSize = this._stashInitialSize;
this._createLoader();
this._loader.open(this._dataSource, requestRange);
if (this._onSeeked) {
this._onSeeked();
}
}
updateUrl(url) {
if (!url || typeof url !== 'string' || url.length === 0) {
throw new InvalidArgumentException('Url must be a non-empty string!');
}
this._dataSource.url = url;
// TODO: replace with new url
}
_expandBuffer(expectedBytes) {
let bufferNewSize = this._stashSize;
while (bufferNewSize + 1024 * 1024 * 1 < expectedBytes) {
bufferNewSize *= 2;
}
bufferNewSize += 1024 * 1024 * 1; // bufferSize = stashSize + 1MB
if (bufferNewSize === this._bufferSize) {
return;
}
View on GitHub (pinned to 42343088f2)
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.
Example fix
// before
controller.updateUrl(urlFromServer);
// after
if (typeof urlFromServer === 'string' && urlFromServer.length > 0) {
controller.updateUrl(urlFromServer);
} Defensive patterns
Strategy: validation
Validate before calling
function canUpdateUrl(url) {
return typeof url === 'string' && url.length > 0;
}
if (canUpdateUrl(newUrl)) ioController.updateUrl(newUrl); Type guard
function isNonEmptyString(v) {
return typeof v === 'string' && v.length > 0;
} Try / catch
try {
ioController.updateUrl(candidate);
} catch (e) {
if (e.name === 'InvalidArgumentException') console.warn('Invalid URL skipped:', candidate);
else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.
Related errors
- FlvPlayer requires an flv MediaDataSource input!
- HTMLMediaElement must be attached before load()!
- FlvPlayer.load() has been called, please call unload() first
- NativePlayer does't support flv MediaDataSource input!
AI-assisted analysis of bilibili/flv.js@42343088f2 (2026-09-01).
Data as JSON: /api/errors/ec33ad209ab2e413.
Report an issue: GitHub.