jackwener/OpenCLI · error · ArgumentError
player is required
Error message
player is required
What it means
This ArgumentError is thrown by parsePlayerRef in clis/hltv/utils.js when the player reference argument is empty. parsePlayerRef normalizes String(value ?? defaultValue).trim(); if the resulting string is empty — even though a default of '3741/niko' exists — the function refuses to proceed because it cannot build a valid HLTV player identity ({playerId, slug}). It indicates a programming/config mistake: an empty string or whitespace-only value was passed explicitly.
Source
Thrown at clis/hltv/utils.js:178
let path = raw;
if (/^https?:\/\//i.test(raw)) path = parseHltvUserUrl(raw, 'team').pathname;
path = path.replace(/^https?:\/\/[^/]+/i, '').replace(/^\/+/, '');
const statsMatch = path.match(/^stats\/teams(?:\/matches)?\/(\d+)\/([a-z0-9-]+)/i);
const teamMatch = path.match(/^team\/(\d+)\/([a-z0-9-]+)/i);
const compactMatch = path.match(/^(\d+)\/([a-z0-9-]+)$/i);
const match = statsMatch || teamMatch || compactMatch;
if (!match) {
throw new ArgumentError('team must be like 6667/falcons, a team URL, or a stats team URL');
}
return { teamId: match[1], slug: match[2].toLowerCase() };
}
export function parsePlayerRef(value, defaultValue = '3741/niko') {
const raw = String(value ?? defaultValue).trim();
if (!raw) throw new ArgumentError('player is required');
let path = raw;
if (/^https?:\/\//i.test(raw)) path = parseHltvUserUrl(raw, 'player').pathname;
path = path.replace(/^https?:\/\/[^/]+/i, '').replace(/^\/+/, '');
const statsMatch = path.match(/^stats\/players(?:\/matches)?\/(\d+)\/([a-z0-9-]+)/i);
const playerMatch = path.match(/^player\/(\d+)\/([a-z0-9-]+)/i);
const compactMatch = path.match(/^(\d+)\/([a-z0-9-]+)$/i);
const match = statsMatch || playerMatch || compactMatch;
if (!match) {
throw new ArgumentError('player must be like 3741/niko, a player URL, or a stats player URL');
}
return { playerId: match[1], slug: match[2].toLowerCase() };
}
function formatDate(date) {
const yyyy = date.getUTCFullYear();View on GitHub (pinned to 49907e53dc)
Solutions
- Remove the empty argument so null/undefined falls back to the default '3741/niko', or pass a valid ref like '3741/niko'.
- Check where the value originates (env var, CLI arg, config) and default it to null/undefined instead of '' before calling.
- Trim and validate the input before calling: if (!input?.trim()) skip or substitute a real player ref.
Example fix
// before buildPlayerUrl(process.env.PLAYER ?? ''); // throws if PLAYER='' // after const ref = process.env.PLAYER?.trim() ? process.env.PLAYER : undefined; buildPlayerUrl(ref); // falls back to default '3741/niko'
Defensive patterns
Strategy: validation
Validate before calling
function isValidPlayerRef(v) {
return typeof v === 'string' && v.trim().length > 0;
}
if (!isValidPlayerRef(input)) throw new TypeError('player must be a non-empty string'); Type guard
function hasPlayerRef(v) {
return typeof v === 'string' && v.trim() !== '';
} Try / catch
try {
const { playerId, slug } = parsePlayerRef(input);
} catch (err) {
if (err.name === 'ArgumentError' && err.message === 'player is required') {
// fall back to default player
} else throw err;
} Prevention
- Never pass '' explicitly — pass undefined/null to get the default '3741/niko'.
- Trim env/CLI inputs before use and convert empty strings to undefined at the boundary.
- Coerce with ?? undefined rather than ?? '' when defaulting.
When it happens
Trigger: Calling playerA(''), playerB(' '), or passing { player: '' } into { playerId, slug } — any explicit empty or whitespace-only string. Note that null/undefined fall back to the default, so this fires only when a non-nullish empty value is supplied (or when String() coercion of a value yields an empty string, e.g. an empty array []).
Common situations: Config/env vars like PLAYER_REF='' read as empty strings instead of undefined; shell scripts passing "$VAR" with unset vars; form/CLI inputs not trimmed and defaulted; JSON config with empty fields overriding the built-in default.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- ${label} must be <= ${maxValue}
- player must be like 3741/niko, a player URL, or a stats play
- period must be all, lastMonth, last3Months, last6Months, las
- match is required
- match must be an HLTV match, stats series, or mapstats URL
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/b159a8f5c935ca21.
Report an issue: GitHub.