jackwener/OpenCLI · error · CliError
UNSUPPORTED_TARGET
UNSUPPORTED_TARGET
Error message
UNSUPPORTED_TARGET
What it means
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.
Source
Thrown at clis/zhihu/target.js:87
const articleMatch = url.pathname.match(ARTICLE_PATH_RE);
if (articleMatch) {
return { kind: 'article', id: articleMatch[1], url: `https://zhuanlan.zhihu.com/p/${articleMatch[1]}` };
}
}
}
catch { }
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');
}
export function assertAllowedKinds(command, target) {
const allowed = {
follow: ['user', 'question'],
like: ['answer', 'article'],
favorite: ['answer', 'article'],
comment: ['answer', 'article'],
answer: ['question'],
};
if (!allowed[command]?.includes(target.kind)) {
throw new CliError('UNSUPPORTED_TARGET', `zhihu ${command} does not support ${target.kind} targets`);
}
return target;
}
export const __test__ = { parseTarget, assertAllowedKinds };
View on GitHub (pinned to 49907e53dc)
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
Example fix
// before opencli zhihu like user:some-slug --execute // after opencli zhihu follow user:some-slug --execute
Defensive patterns
Strategy: validation
Validate before calling
const allowed = { follow: ['user','question'], like: ['answer','article'], favorite: ['answer','article'], comment: ['answer','article'], answer: ['question'] };
// derive kind cheaply before invoking
function targetKind(s) {
if (/^answer:\d+:\d+$/.test(s) || /\/answer\//.test(s) || /zhuanlan\.zhihu\.com\/p\//.test(s)) return 'article-like';
if (/^question:\d+$/.test(s) || /\/question\//.test(s)) return 'question';
if (/^user:/.test(s) || /\/people\//.test(s)) return 'user';
return 'unknown';
}
if (!allowed[command]?.some(k => targetKind(target).includes(k) || targetKind(target) === k)) throw new Error(`${command} does not support this target kind`); Type guard
function isAllowedForCommand(command, t) {
const allowed = { follow: ['user','question'], like: ['answer','article'], favorite: ['answer','article'], comment: ['answer','article'], answer: ['question'] };
return Boolean(allowed[command]?.includes(t.kind));
} Try / catch
try {
assertAllowedKinds(command, parseTarget(input));
} catch (err) {
if (err.code === 'UNSUPPORTED_TARGET') {
console.error(`${err.message} — pick a matching command for this target kind`);
} else throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- INVALID_INPUT
- INVALID_INPUT
- 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/3590594bd980ab06.
Report an issue: GitHub.