jackwener/OpenCLI · error · ArgumentError
maven ${label} cannot be empty
Error message
maven ${label} cannot be empty What it means
`requireString` validates that a labeled argument (e.g. 'query') is a non-empty string after trimming; if the value is null, undefined, whitespace, or otherwise stringifies to empty, it throws ArgumentError with `maven ${label} cannot be empty`. The library throws it eagerly so requests are never sent with a blank required parameter.
Source
Thrown at clis/maven/utils.js:18
// Shared helpers for the Maven Central (search.maven.org) adapter.
//
// Hits the public, unauthenticated `search.maven.org/solrsearch/select` Solr
// endpoint that powers the Maven Central search UI. No auth required for
// read-only queries.
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
export const MAVEN_BASE = 'https://search.maven.org/solrsearch/select';
export const MAVEN_REPO_BASE = 'https://repo1.maven.org/maven2';
const UA = 'opencli-maven-adapter (+https://github.com/jackwener/opencli)';
// Maven groupId / artifactId tokens — Java-package-ish (letters / digits /
// `_-.`), 1-200 chars; reverse-DNS dots are allowed in groupId.
const COORD_TOKEN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
export function requireString(value, label) {
const s = String(value ?? '').trim();
if (!s) throw new ArgumentError(`maven ${label} cannot be empty`);
return s;
}
export function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {
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.View on GitHub (pinned to 49907e53dc)
Solutions
- Provide the required argument, e.g. call search with a non-empty query string
- Check where the value originates (CLI flag, env var, config) and ensure it is populated before the call
- Trim/default the value at the boundary if empty input is legitimate in your flow
- Read the error's label to identify which argument was empty ('maven query cannot be empty' -> the query argument)
Example fix
// before
const docs = await mavenSearch({ query: args.q }); // args.q is undefined
// after
const docs = await mavenSearch({ query: requireNonEmpty(args.q, 'jackson-databind') }); Defensive patterns
Strategy: validation
Validate before calling
function requireQuery(q) {
const s = typeof q === 'string' ? q.trim() : '';
if (!s) throw new Error('query must be a non-empty string');
return s;
} Type guard
function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; } Try / catch
try {
const docs = await mavenSearch({ query });
} catch (err) {
if (err instanceof ArgumentError && /cannot be empty/.test(err.message)) {
console.error('Provide a --query value');
process.exitCode = 2;
return;
}
throw err;
} Prevention
- Validate CLI/config inputs at the boundary before calling library functions
- Never pass possibly-undefined values straight through from config or env
- Trim user input and reject whitespace-only strings early
- Use labels/flag defaults so required fields can't be silently empty
When it happens
Trigger: Calling an operation that requires a string argument without providing it, e.g. `query(undefined)`, `query('')`, `query(' ')`, or `query(null)`. For maven search this means calling search with args.query missing or blank.
Common situations: An upstream config field or CLI flag is unset so the value arrives as undefined; a form/template interpolation produced an empty string; code reads the wrong property name (e.g. args.term instead of args.query); whitespace-only input pasted from docs.
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
- maven ${label} must be a positive integer
- maven ${label} must be <= ${maxValue}
- maven coordinate is required (e.g. "com.fasterxml.jackson.co
- maven coordinate "${value}" must be "groupId:artifactId" or
- maven coordinate "${value}" is missing groupId or artifactId
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/33e7436ea1c3807a.
Report an issue: GitHub.