{"record":{"id":"3590594bd980ab06","repo":"jackwener/OpenCLI","slug":"unsupported-target","errorCode":"UNSUPPORTED_TARGET","errorMessage":"UNSUPPORTED_TARGET","messagePattern":"UNSUPPORTED_TARGET","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/target.js","lineNumber":87,"sourceCode":"            const articleMatch = url.pathname.match(ARTICLE_PATH_RE);\n            if (articleMatch) {\n                return { kind: 'article', id: articleMatch[1], url: `https://zhuanlan.zhihu.com/p/${articleMatch[1]}` };\n            }\n        }\n    }\n    catch { }\n    throw new CliError('INVALID_INPUT', 'Zhihu write commands require a Zhihu URL or typed target like question:123 or answer:123:456', 'Example: opencli zhihu like answer:123:456 --execute');\n}\nexport function assertAllowedKinds(command, target) {\n    const allowed = {\n        follow: ['user', 'question'],\n        like: ['answer', 'article'],\n        favorite: ['answer', 'article'],\n        comment: ['answer', 'article'],\n        answer: ['question'],\n    };\n    if (!allowed[command]?.includes(target.kind)) {\n        throw new CliError('UNSUPPORTED_TARGET', `zhihu ${command} does not support ${target.kind} targets`);\n    }\n    return target;\n}\nexport const __test__ = { parseTarget, assertAllowedKinds };\n","sourceCodeStart":69,"sourceCodeEnd":92,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/target.js#L69-L92","documentation":"assertAllowedKinds maps each zhihu write command to the target kinds it accepts: follow accepts user/question; like, favorite and comment accept answer/article; answer accepts question. If the parsed target's kind is not in the command's allow-list, it throws CliError with code UNSUPPORTED_TARGET, naming the command and kind.","triggerScenarios":"Calling e.g. 'opencli zhihu follow answer:123:456', 'opencli zhihu like user:someone', or 'opencli zhihu answer https://zhuanlan.zhihu.com/p/1' — the target parses fine but its kind is not permitted for that command.","commonSituations":"Mixing up which entities a command operates on (liking a user, following an answer), scripting commands with variables that hold the wrong target type, assuming comment works on questions.","solutions":["Match the command to the target kind: use follow for user/question, like/favorite/comment for answer/article, answer for question","Re-parse with a target of an allowed kind, e.g. 'opencli zhihu follow question:123 --execute'","Check the command's help output for supported target types"],"exampleFix":"// before\nopencli zhihu like user:some-slug --execute\n// after\nopencli zhihu follow user:some-slug --execute","handlingStrategy":"validation","validationCode":"const allowed = { follow: ['user','question'], like: ['answer','article'], favorite: ['answer','article'], comment: ['answer','article'], answer: ['question'] };\n// derive kind cheaply before invoking\nfunction targetKind(s) {\n  if (/^answer:\\d+:\\d+$/.test(s) || /\\/answer\\//.test(s) || /zhuanlan\\.zhihu\\.com\\/p\\//.test(s)) return 'article-like';\n  if (/^question:\\d+$/.test(s) || /\\/question\\//.test(s)) return 'question';\n  if (/^user:/.test(s) || /\\/people\\//.test(s)) return 'user';\n  return 'unknown';\n}\nif (!allowed[command]?.some(k => targetKind(target).includes(k) || targetKind(target) === k)) throw new Error(`${command} does not support this target kind`);","typeGuard":"function isAllowedForCommand(command, t) {\n  const allowed = { follow: ['user','question'], like: ['answer','article'], favorite: ['answer','article'], comment: ['answer','article'], answer: ['question'] };\n  return Boolean(allowed[command]?.includes(t.kind));\n}","tryCatchPattern":"try {\n  assertAllowedKinds(command, parseTarget(input));\n} catch (err) {\n  if (err.code === 'UNSUPPORTED_TARGET') {\n    console.error(`${err.message} — pick a matching command for this target kind`);\n  } else throw err;\n}","preventionTips":["Check the command/help matrix before scripting: follow→user/question, like/favorite/comment→answer/article, answer→question","Parse the target first and branch on its kind when generating commands","Write a small table-driven guard in wrapper scripts","Don't assume all write commands accept all entity types"],"tags":["zhihu","input-validation","command-target-mismatch"],"backgroundTag":"unsupported-target-type","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}