jackwener/OpenCLI · error · CliError
INVALID_INPUT
INVALID_INPUT
Error message
INVALID_INPUT
What it means
parseZhihuUser resolves a user argument (bare url_token, 'user:<slug>', or a people URL) to a slug. If the input trims to an empty string, it throws CliError with code INVALID_INPUT because no Zhihu user can be identified. Empty input cannot match any accepted format, so it fails immediately with an example usage.
Source
Thrown at clis/zhihu/user-arg.js:15
import { CliError } from '@jackwener/opencli/errors';
const SLUG_RE = /^[A-Za-z0-9_-]+$/;
const USER_PREFIX_RE = /^user:([A-Za-z0-9_-]+)$/;
const PEOPLE_PATH_RE = /^\/people\/([A-Za-z0-9_-]+)\/?$/;
/**
* Parse a Zhihu user identifier for read commands.
* Accepts a bare url_token (`wen-jie-16-47`), the `user:<slug>` form, or a
* full people URL (`https://www.zhihu.com/people/<slug>`). Returns the slug.
*/
export function parseZhihuUser(input) {
const value = String(input ?? '').trim();
if (!value) {
throw new CliError('INVALID_INPUT', 'A Zhihu user is required', 'Example: opencli zhihu user wen-jie-16-47');
}
const prefixMatch = value.match(USER_PREFIX_RE);
if (prefixMatch) return prefixMatch[1];
if (SLUG_RE.test(value)) return value;
try {
const url = new URL(value);
if (url.protocol === 'https:' && url.hostname === 'www.zhihu.com') {
const m = url.pathname.match(PEOPLE_PATH_RE);
if (m) return m[1];
}
} catch {
// fall through to the typed error below
}
throw new CliError(
'INVALID_INPUT',
`Invalid Zhihu user: ${value}`,
'Use a url_token (wen-jie-16-47) or a people URL (https://www.zhihu.com/people/wen-jie-16-47)',
);View on GitHub (pinned to 49907e53dc)
Solutions
- Provide a user: bare slug (wen-jie-16-47), user:<slug>, or https://www.zhihu.com/people/<slug>
- Check the shell variable you interpolated is actually set and non-empty
- Quote arguments and verify with the command's --help for the expected positional argument
Example fix
// before opencli zhihu user answers "$ZHIHU_USER" # ZHIHU_USER unset // after ZHIHU_USER=wen-jie-16-47 opencli zhihu user answers "$ZHIHU_USER"
Defensive patterns
Strategy: validation
Validate before calling
function requireZhihuUser(input) {
const v = String(input ?? '').trim();
if (!v) throw new Error('a zhihu user slug or people URL is required');
return v;
}
const user = requireZhihuUser(process.argv[3]); Type guard
function isNonEmptyString(v) {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
const slug = parseZhihuUser(userArg);
} catch (err) {
if (err.code === 'INVALID_INPUT') {
console.error('Provide a user: e.g. opencli zhihu user wen-jie-16-47');
} else throw err;
} Prevention
- Check positional arguments for emptiness before invoking commands
- Quote and default shell variables: "${ZHIHU_USER:?unset}"
- Pass the bare url_token or a full people URL, never empty strings
- In scripts, validate required args exist and exit early with usage text
When it happens
Trigger: Calling a command requiring a user argument with an empty string, only whitespace, an unset shell variable (e.g. $USER empty), or null/undefined coerced via String(input ?? '').
Common situations: Unquoted empty shell variables, scripting pipelines where a variable was never assigned, forgetting the positional argument entirely (framework may pass empty string), copy-paste losing the username.
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_INPUT
- UNSUPPORTED_TARGET
- Unknown 12306 station telecode "${trimmed}"
- Unknown 12306 station "${trimmed}"
- date must be YYYY-MM-DD, got "${value}"
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d8ef959d71c6b1c5.
Report an issue: GitHub.