jackwener/OpenCLI · error · CliError
INVALID_ARGUMENT
INVALID_ARGUMENT
Error message
Keyword is required
What it means
CliError with code INVALID_ARGUMENT thrown when the gitee search command receives no usable keyword. args.keyword is coerced to string and trimmed; if the result is empty, the library throws before making any network request, with hint 'Provide a search keyword'.
Source
Thrown at clis/gitee/search.js:80
}
}
cli({
site: 'gitee',
name: 'search',
access: 'read',
description: 'Search repositories on Gitee',
domain: 'gitee.com',
strategy: Strategy.PUBLIC,
browser: true,
args: [
{ name: 'keyword', positional: true, required: true, help: 'Search keyword' },
{ name: 'limit', type: 'int', default: 10, help: 'Number of results (max 50)' },
],
columns: ['rank', 'name', 'language', 'stars', 'description', 'url'],
func: async (page, args) => {
const keyword = String(args.keyword ?? '').trim();
if (!keyword) {
throw new CliError('INVALID_ARGUMENT', 'Keyword is required', 'Provide a search keyword');
}
const limit = clampLimit(args.limit);
const encodedKeyword = encodeURIComponent(keyword);
const searchUrl = `${GITEE_SEARCH_URL}?q=${encodedKeyword}&type=repository`;
const fetchSize = Math.max(10, limit);
const apiUrl = new URL(GITEE_SEARCH_API);
apiUrl.searchParams.set('q', keyword);
apiUrl.searchParams.set('from', '0');
apiUrl.searchParams.set('size', String(fetchSize));
await page.goto(searchUrl);
await page.wait(2);
const response = await fetch(apiUrl.toString(), {
headers: {
Accept: 'application/json',
'User-Agent': 'Mozilla/5.0',
Referer: searchUrl,
},
});View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a non-empty keyword, e.g. `opencli gitee search --keyword redis`
- Quote shell variables and check they are non-empty before invoking: [ -n "$KEYWORD" ] || exit 1
- Check flag spelling so args.keyword is actually populated (keyword vs query/q)
- Handle the INVALID_ARGUMENT code in your wrapper to print usage
Example fix
// before opencli gitee search --keyword "" # Keyword is required // after opencli gitee search --keyword "redis cache" --limit 10
Defensive patterns
Strategy: validation
Validate before calling
const keyword = String(process.argv[2] ?? '').trim();
if (!keyword) {
console.error('Usage: opencli gitee search <keyword>');
process.exit(1);
} Type guard
function hasKeyword(a) {
return typeof a === 'string' && a.trim().length > 0;
} Try / catch
try {
await giteeSearch(keyword);
} catch (e) {
if (e.code === 'INVALID_ARGUMENT') {
console.error('Keyword is required. Usage: opencli gitee search <keyword>');
process.exit(1);
}
throw e;
} Prevention
- Always pass a quoted, non-empty keyword argument
- Validate/trim inputs in wrapper scripts before calling the CLI
- Use consistent flag names (keyword) to avoid undefined args
- Fail fast with usage output when required args are absent
When it happens
Trigger: Calling `opencli gitee search` (or the JS func) with keyword missing, an empty string, or a whitespace-only value like ' ' or args.keyword being undefined/null.
Common situations: Forgetting the positional/keyword argument in a shell script; passing an unquoted empty variable ('$KEYWORD' expanding to ''); piping pipelines where an upstream step produced an empty value; typos in the flag name so args.keyword is undefined.
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
- INVALID_ARGUMENT
- Collection name cannot be empty
- series_id must be a non-empty value
- Invalid Chess.com username "${value}" Usernames are 3-25 cha
- coingecko derivatives limit must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/90dde38ea62d1895.
Report an issue: GitHub.