jackwener/OpenCLI · error · ArgumentError

team is required

Error message

team is required

What it means

parseTeamRef requires a team reference — either 'id/slug' (6667/falcons), an hltv.org /team/:id/:slug URL, or a stats /stats/teams/:id/:slug URL. It throws this immediately when the resolved value is an empty string after trimming, i.e. no team was supplied and no default applied.

Source

Thrown at clis/hltv/utils.js:159

  let url = null;
  if (/^https?:\/\//i.test(raw)) url = parseHltvUserUrl(raw, 'event');
  if (url?.searchParams.get('event')) {
    const eventId = url.searchParams.get('event');
    if (/^\d+$/.test(eventId)) return eventId;
    throw new ArgumentError('event query parameter must be a numeric event id');
  }

  const path = (url ? url.pathname : raw).replace(/^\/+/, '');
  const eventPath = path.match(/^events\/(\d+)\//i);
  if (eventPath) return eventPath[1];

  throw new ArgumentError('event must be an event id, an /events/:id URL, a stats URL with event=, or all');
}

export function parseTeamRef(value, defaultValue = null) {
  const raw = String(value ?? defaultValue ?? '').trim();
  if (!raw) throw new ArgumentError('team is required');

  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();

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Supply a team reference such as --team 6667/falcons
  2. Use a full team URL like https://www.hltv.org/team/6667/falcons or the stats variant
  3. Check that the script/config actually populates the team value

Example fix

// before
hltv team-matches   # --team missing
// after
hltv team-matches --team 6667/falcons
Defensive patterns

Strategy: validation

Validate before calling

if (!opts.team || !String(opts.team).trim()) throw new Error('--team is required, e.g. 6667/falcons');

Type guard

const hasTeamRef = (v) => typeof v === 'string' && v.trim().length > 0;

Try / catch

try {
  await hltv.teamMatches({ team: cfg.team });
} catch (e) {
  if (e.name === 'ArgumentError' && e.message === 'team is required') {
    console.error('Set --team or TEAM env var');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Calling a command with --team '' or omitting --team on a subcommand where it is mandatory; a script variable holding the team is unset.

Common situations: Missing CLI flag; empty environment variable interpolated into the command; config file with team: ""; refactor removed the hardcoded default.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/b634ddabd0e48a47. Report an issue: GitHub.