{"record":{"id":"5c3c7ab6564ced59","repo":"jackwener/OpenCLI","slug":"zhihu-search-type-must-be-one-of-types-join","errorCode":null,"errorMessage":"zhihu search --type must be one of: ${TYPES.join(', ')}","messagePattern":"zhihu search --type must be one of: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/search.js","lineNumber":65,"sourceCode":"    const limit = Number(value ?? 10);\n    if (!Number.isInteger(limit) || limit <= 0 || limit > MAX_LIMIT) {\n        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');\n    }\n    return limit;\n}\n\nfunction requireQuery(value) {\n    const query = String(value || '').trim();\n    if (!query) {\n        throw new ArgumentError('zhihu search query must not be empty', 'Example: opencli zhihu search codex');\n    }\n    return query;\n}\n\nfunction requireType(value) {\n    const type = String(value || 'all');\n    if (!TYPES.includes(type)) {\n        throw new ArgumentError(`zhihu search --type must be one of: ${TYPES.join(', ')}`, 'Example: opencli zhihu search codex --type answer');\n    }\n    return type;\n}\n\nfunction unwrapEvaluateResult(payload) {\n    if (payload && typeof payload === 'object' && 'data' in payload && 'session' in payload) return payload.data;\n    return payload;\n}\n\nfunction requireSearchPayload(data, url) {\n    const payload = unwrapEvaluateResult(data);\n    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {\n        throw new CommandExecutionError('Zhihu search returned malformed payload');\n    }\n    if (payload.__httpError) {\n        const status = payload.__httpError;\n        if (status === 401 || status === 403) {\n            throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch search results from Zhihu');","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/search.js#L47-L83","documentation":"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.","triggerScenarios":"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.","commonSituations":"Guessing type names instead of using --help; pluralizing or capitalizing a valid value; copying types from another search CLI; shell completion not available.","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'"],"exampleFix":"// before\nopencli zhihu search codex --type Answers\n// after\nopencli zhihu search codex --type answer","handlingStrategy":"validation","validationCode":"const TYPES = ['all', 'answer', 'article', 'question'];\nif (!TYPES.includes(rawType)) throw new Error(`--type must be one of: ${TYPES.join(', ')}`);","typeGuard":"function isValidType(v) {\n  return ['all', 'answer', 'article', 'question'].includes(v);\n}","tryCatchPattern":"try {\n  await runSearch({ type: rawType });\n} catch (err) {\n  if (err instanceof ArgumentError && err.message.includes('--type')) {\n    console.error('Valid types: all, answer, article, question. Falling back to all.');\n    return runSearch({ type: 'all' });\n  }\n  throw err;\n}","preventionTips":["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"],"tags":["cli","argument-validation","zhihu","enum-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}