jackwener/OpenCLI · error · ArgumentError
zhihu search --type must be one of: ${TYPES.join(', ')}
Error message
zhihu search --type must be one of: ${TYPES.join(', ')} What it means
requireType in clis/zhihu/search.js throws ArgumentError when --type is not one of the allowed values: all, answer, article, question (the TYPES array). The type value is sent to Zhihu's search endpoint, so only these exact strings are accepted.
Source
Thrown at clis/zhihu/search.js:65
const limit = Number(value ?? 10);
if (!Number.isInteger(limit) || limit <= 0 || limit > MAX_LIMIT) {
throw new ArgumentError(`zhihu search --limit must be a positive integer no greater than ${MAX_LIMIT}`, 'Use a normal-sized limit to avoid slow requests or Zhihu risk controls');
}
return limit;
}
function requireQuery(value) {
const query = String(value || '').trim();
if (!query) {
throw new ArgumentError('zhihu search query must not be empty', 'Example: opencli zhihu search codex');
}
return query;
}
function requireType(value) {
const type = String(value || 'all');
if (!TYPES.includes(type)) {
throw new ArgumentError(`zhihu search --type must be one of: ${TYPES.join(', ')}`, 'Example: opencli zhihu search codex --type answer');
}
return type;
}
function unwrapEvaluateResult(payload) {
if (payload && typeof payload === 'object' && 'data' in payload && 'session' in payload) return payload.data;
return payload;
}
function requireSearchPayload(data, url) {
const payload = unwrapEvaluateResult(data);
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
throw new CommandExecutionError('Zhihu search returned malformed payload');
}
if (payload.__httpError) {
const status = payload.__httpError;
if (status === 401 || status === 403) {
throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch search results from Zhihu');View on GitHub (pinned to 49907e53dc)
Solutions
- Use one of the exact values: all, answer, article, or question
- Check clis/zhihu/search.js TYPES array or the CLI help for the accepted list
- Lowercase the value — matching is case-sensitive (String(value || 'all'))
- Omit --type to get the default 'all'
Example fix
// before opencli zhihu search codex --type Answers // after opencli zhihu search codex --type answer
Defensive patterns
Strategy: validation
Validate before calling
const TYPES = ['all', 'answer', 'article', 'question'];
if (!TYPES.includes(rawType)) throw new Error(`--type must be one of: ${TYPES.join(', ')}`); Type guard
function isValidType(v) {
return ['all', 'answer', 'article', 'question'].includes(v);
} Try / catch
try {
await runSearch({ type: rawType });
} catch (err) {
if (err instanceof ArgumentError && err.message.includes('--type')) {
console.error('Valid types: all, answer, article, question. Falling back to all.');
return runSearch({ type: 'all' });
}
throw err;
} Prevention
- Use shell completion or --help to list valid --type values
- Lowercase type input before passing it in (matching is case-sensitive)
- Omit --type when you want the default 'all' behavior
When it happens
Trigger: Running `opencli zhihu search <query> --type` with a value outside TYPES, e.g. --type answers (plural), --type Answer (case-sensitive check), --type video, or any typo.
Common situations: Guessing type names instead of using --help; pluralizing or capitalizing a valid value; copying types from another search CLI; shell completion not available.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- indeed fromage must be one of 1/3/7/14 (days), got "${value}
- indeed sort must be "relevance" or "date", got "${value}"
- zhihu search --limit must be a positive integer no greater t
- zhihu search query must not be empty
- <train-no> "${trainNo}" does not look like a 12306 internal
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/5c3c7ab6564ced59.
Report an issue: GitHub.