jackwener/OpenCLI · error · CliError
INVALID_ARGUMENT
INVALID_ARGUMENT
Error message
Username is required
What it means
CliError with code INVALID_ARGUMENT thrown when the gitee user command receives no usable username. args.username is sanitized (trimmed/stripped); if empty, the command throws before navigating, with usage hint 'Use: opencli gitee user <username>'.
Source
Thrown at clis/gitee/user.js:82
}
return '';
}
cli({
site: 'gitee',
name: 'user',
access: 'read',
description: 'Show a Gitee user profile panel',
domain: 'gitee.com',
strategy: Strategy.PUBLIC,
browser: true,
args: [
{ name: 'username', positional: true, required: true, help: 'Gitee username' },
],
columns: ['field', 'value'],
func: async (page, args) => {
const username = sanitizeUsername(String(args.username ?? ''));
if (!username) {
throw new CliError('INVALID_ARGUMENT', 'Username is required', 'Use: opencli gitee user <username>');
}
const profileUrl = `${GITEE_BASE_URL}/${encodeURIComponent(username)}`;
await page.goto(profileUrl);
await page.wait(2);
const rawDomSnapshot = await page.evaluate(`
(() => {
const normalize = (value) => (value || '').replace(/\\s+/g, ' ').trim();
const extractCount = (value) => {
const text = normalize(value).replace(/,/g, '');
if (!text) return '';
const match = text.match(/\\d+(?:[.]\\d+)?(?:\\s*[kKmMwW\\u4E07])?/);
return match ? match[0].replace(/\\s+/g, '') : '';
};
const title = normalize(document.title || '');
const bodyText = normalize(document.body?.innerText || '');
const notFound = /404|页面不存在|资源不存在|page not found/i.test(title + ' ' + bodyText);
const blocked = /访问受限|没有访问权限|forbidden|denied/i.test(bodyText);View on GitHub (pinned to 49907e53dc)
Solutions
- Pass the username positionally: `opencli gitee user <username>`
- Validate the argument is non-empty in your wrapper before invoking
- Pass just the handle, not a full URL, if sanitization removes the prefix
- Print usage (per the hint) when INVALID_ARGUMENT code is caught
Example fix
// before opencli gitee user "" # Username is required // after opencli gitee user mindspore
Defensive patterns
Strategy: validation
Validate before calling
const username = String(process.argv[2] ?? '').trim();
if (!/^[A-Za-z0-9_-]+$/.test(username)) {
console.error('Usage: opencli gitee user <username>');
process.exit(1);
} Type guard
function hasUsername(a) {
return typeof a === 'string' && a.trim().length > 0;
} Try / catch
try {
await giteeUser(username);
} catch (e) {
if (e.code === 'INVALID_ARGUMENT') {
console.error('Username is required. Use: opencli gitee user <username>');
process.exit(1);
}
throw e;
} Prevention
- Always pass the positional username argument, quoted
- Pass the login handle, not a full profile URL or email
- Validate argument presence in wrapper scripts before invoking
- Print usage text on empty/invalid usernames
When it happens
Trigger: Calling `opencli gitee user` without the required positional username, or passing only whitespace or characters that sanitize to an empty string (e.g. '/').
Common situations: Forgetting the positional argument in scripts; an upstream variable holding the username is empty; passing a full profile URL where only the handle is expected and the sanitizer strips it to nothing; quoting mistakes dropping the argument.
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/6c87d6f6c64d88ff.
Report an issue: GitHub.