jackwener/OpenCLI · error · ArgumentError
player must be like 3741/niko, a player URL, or a stats play
Error message
player must be like 3741/niko, a player URL, or a stats player URL
What it means
This ArgumentError is thrown by parsePlayerRef when the player string is non-empty but matches none of the accepted formats: compact 'id/slug', '/player/id/slug', or '/stats/players(/matches)/id/slug' paths (URLs are reduced to their pathname first). It means the library could not extract a numeric playerId and slug from the input. HLTV players are identified by the id/slug pair, so an unparseable ref cannot be turned into a stats URL.
Source
Thrown at clis/hltv/utils.js:189
}
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();
const mm = String(date.getUTCMonth() + 1).padStart(2, '0');
const dd = String(date.getUTCDate()).padStart(2, '0');
return `${yyyy}-${mm}-${dd}`;
}
function addMonths(date, months) {
const copy = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()));
copy.setUTCMonth(copy.getUTCMonth() + months);
return copy;
}
View on GitHub (pinned to 49907e53dc)
Solutions
- Pass the full ref in a supported form: '3741/niko', 'player/3741/niko', 'stats/players/3741/niko', or a full URL like https://www.hltv.org/player/3741/niko.
- Look up the numeric player id on HLTV and append the URL slug; a nickname alone is not an accepted format.
- Verify the URL is a player page (path starts with /player/<digits>/ or /stats/players/...), not a team or match page.
- Strip query strings/fragments and trailing slashes if constructing the ref manually.
Example fix
// before
buildPlayerUrl('niko'); // ArgumentError
// after
buildPlayerUrl('3741/niko');
// or
buildPlayerUrl('https://www.hltv.org/player/3741/niko'); Defensive patterns
Strategy: validation
Validate before calling
const PLAYER_REF_RE = /^(?:https?:\/\/[^/]+)?\/?\s*(?:stats\/players(?:\/matches)?|player)?\/(\d+)\/([a-z0-9-]+)/i;
function isParsablePlayerRef(v) {
const s = String(v ?? '').replace(/^https?:\/\/[^/]+/i, '').replace(/^\/+/, '');
return /^(stats\/players(?:\/matches)?\/\d+\/[a-z0-9-]+|player\/\d+\/[a-z0-9-]+|\d+\/[a-z0-9-]+)$/i.test(s);
}
if (!isParsablePlayerRef(input)) throw new TypeError('player ref must be id/slug or a player/stats-player URL'); Type guard
function isPlayerRef(v) {
return typeof v === 'string' && /^(?:stats\/players(?:\/matches)?\/\d+|player\/\d+|\d+)\/[a-z0-9-]+/i.test(v.replace(/^https?:\/\/[^/]+/i, '').replace(/^\/+/, ''));
} Try / catch
try {
return buildPlayerUrl(input);
} catch (err) {
if (err.name === 'ArgumentError' && err.message.startsWith('player must be like')) {
throw new Error(`Unsupported player ref "${input}" — use id/slug or a HLTV player URL`, { cause: err });
}
throw err;
} Prevention
- Always carry both the numeric id and the slug; a nickname alone is never enough.
- Normalize URLs to pathname + strip query/fragment before validating shape.
- Keep player and team refs in separate fields so formats don't get crossed.
- Unit-test refs with the same regex family used by the library (stats/player/compact patterns).
When it happens
Trigger: playerA('niko'), playerB('3741'), { player: 'hltv.org/player' }, a URL whose pathname lacks the id/slug pair (e.g. /stats/players or a team URL), or slug containing characters outside [a-z0-9-].
Common situations: Passing only a nickname ('niko') or only an id; pasting a profile URL with a trailing fragment that breaks parsing; mixing up team and player refs; older code paths passing 'players/3741/niko' (plural) which no pattern matches.
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
- match must be an HLTV match, stats series, or mapstats URL
- '${rawInput}' does not look like an autohome series id (a nu
- bilibili follow target must be a valid space.bilibili.com/<u
- chatgpt project commands require a chatgpt.com project id or
- Invalid Chess.com game URL: "${value}" Expected https://www.
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/e4c2570fcca0b90d.
Report an issue: GitHub.