jackwener/OpenCLI · error · ArgumentError

maven coordinate is required (e.g. "com.fasterxml.jackson.co

Error message

maven coordinate is required (e.g. "com.fasterxml.jackson.core:jackson-databind")

What it means

`requireCoord` parses a Maven coordinate string `groupId:artifactId[:version]` and throws ArgumentError 'maven coordinate is required (e.g. "com.fasterxml.jackson.core:jackson-databind")' when the input is missing, null, or whitespace-only after trimming. The library requires an explicit coordinate for coordinate-based lookups (info/version resolution for groupId, artifactId, version).

Source

Thrown at clis/maven/utils.js:41

    const raw = value ?? defaultValue;
    const n = typeof raw === 'number' ? raw : Number(raw);
    if (!Number.isInteger(n) || n <= 0) {
        throw new ArgumentError(`maven ${label} must be a positive integer`);
    }
    if (n > maxValue) {
        throw new ArgumentError(`maven ${label} must be <= ${maxValue}`);
    }
    return n;
}

/**
 * Parse a Maven coordinate `groupId:artifactId[:version]` into segments.
 * groupId / artifactId are required; version is optional.
 */
export function requireCoord(value) {
    const raw = String(value ?? '').trim();
    if (!raw) {
        throw new ArgumentError('maven coordinate is required (e.g. "com.fasterxml.jackson.core:jackson-databind")');
    }
    const parts = raw.split(':');
    if (parts.length < 2 || parts.length > 3) {
        throw new ArgumentError(
            `maven coordinate "${value}" must be "groupId:artifactId" or "groupId:artifactId:version"`,
        );
    }
    const [groupId, artifactId, version] = parts;
    if (!groupId || !artifactId) {
        throw new ArgumentError(`maven coordinate "${value}" is missing groupId or artifactId`);
    }
    if (groupId.length > 200 || !COORD_TOKEN.test(groupId)) {
        throw new ArgumentError(
            `maven groupId "${groupId}" is not a valid token`,
            'Use letters / digits / "_-." (max 200 chars), starting with a letter or digit.',
        );
    }
    if (artifactId.length > 200 || !COORD_TOKEN.test(artifactId)) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a full coordinate string like 'com.fasterxml.jackson.core:jackson-databind' (or with version: 'com.fasterxml.jackson.core:jackson-databind:2.16.1')
  2. Check the argument wiring: ensure the value is read from the correct CLI flag/config key and is non-empty
  3. Validate the coordinate format before calling: exactly 2 or 3 colon-separated non-empty segments
  4. If the coordinate is user-supplied, prompt or fail early with a usage message showing the expected format

Example fix

// before
const info = await mavenInfo({ coord: process.env.COORD }); // COORD unset -> ''
// after
if (!process.env.COORD) throw new Error('COORD must be set, e.g. com.fasterxml.jackson.core:jackson-databind');
const info = await mavenInfo({ coord: process.env.COORD });
Defensive patterns

Strategy: validation

Validate before calling

function isValidCoord(v) {
  const s = typeof v === 'string' ? v.trim() : '';
  if (!s) return false;
  const parts = s.split(':');
  return parts.length === 2 || parts.length === 3;
}
if (!isValidCoord(args.coord)) throw new Error('coord required: groupId:artifactId[:version]');

Type guard

function isMavenCoord(v) { return typeof v === 'string' && /^[^:\s]+:[^:\s]+(:[^:\s]+)?$/.test(v.trim()); }

Try / catch

try {
  const info = await mavenInfo({ coord });
} catch (err) {
  if (err instanceof ArgumentError && /coordinate is required/.test(err.message)) {
    console.error('Usage: maven info <groupId:artifactId[:version]>');
    process.exitCode = 2;
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling a coordinate-based operation (e.g. artifact info) with no coordinate argument: `requireCoord(undefined)`, `requireCoord('')`, `requireCoord(' ')`, or `requireCoord(null)` — typically args.coord missing entirely.

Common situations: A CLI invocation omitted the positional coordinate argument; a config key mismatch means the value is read from the wrong field; an automation script builds the coordinate from variables that are empty; user ran the tool without supplying the groupId:artifactId.

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/0fd99d1b887231b1. Report an issue: GitHub.