jackwener/OpenCLI · error · CliError
INVALID_INPUT
INVALID_INPUT
Error message
INVALID_INPUT
What it means
Zhihu write commands are destructive-ish actions gated behind an explicit opt-in. requireExecute checks kwargs.execute and throws CliError('INVALID_INPUT', 'This Zhihu write command requires --execute') when the command was invoked without it — a dry-run-by-default safety design.
Source
Thrown at clis/zhihu/write-shared.js:94
for (const root of roots) {
for (const node of Array.from(root.querySelectorAll(PROFILE_LINK_SELECTOR)).filter(isIdentityNodeLike)) {
const slug = getSlugFromIdentityLink(node, allowAvatarOnly);
if (slug)
return slug;
}
}
return null;
}
export function resolveCurrentUserSlugFromDom(state, documentRoot) {
const slugFromState = resolveSlugFromState(state);
if (slugFromState)
return slugFromState;
const navScopes = Array.from(documentRoot.querySelectorAll(NAV_SCOPE_SELECTOR)).filter(isIdentityRootLike);
return findCurrentUserSlugFromRoots(navScopes, true) || findCurrentUserSlugFromRoots([documentRoot], false);
}
export function requireExecute(kwargs) {
if (!kwargs.execute) {
throw new CliError('INVALID_INPUT', 'This Zhihu write command requires --execute');
}
}
export async function resolvePayload(kwargs, deps = defaultFileReaderDeps()) {
const text = typeof kwargs.text === 'string' ? kwargs.text : undefined;
const file = typeof kwargs.file === 'string' ? kwargs.file : undefined;
if (text && file) {
throw new CliError('INVALID_INPUT', 'Use either <text> or --file, not both');
}
let resolved = text ?? '';
if (file) {
let fileStat;
try {
fileStat = await deps.stat(file);
}
catch {
throw new CliError('INVALID_INPUT', `File not found: ${file}`);
}
if (!fileStat.isFile()) {View on GitHub (pinned to 49907e53dc)
Solutions
- Add --execute to the command line to actually perform the write
- Pass execute: true when invoking programmatically
- Run without --execute intentionally to preview (dry-run) the payload
- Fix argument quoting in scripts so --execute is forwarded
Example fix
// before node cli.js zhihu write-answer --text 'hello' // after node cli.js zhihu write-answer --text 'hello' --execute
Defensive patterns
Strategy: validation
Validate before calling
// in wrapper scripts, assert the flag before invoking
if (!process.argv.includes('--execute')) {
console.error('Refusing to run: --execute is required for Zhihu write commands');
process.exit(2);
} Try / catch
try {
await runZhihuWrite(args);
} catch (e) {
if (e.code === 'INVALID_INPUT' && /--execute/.test(e.message)) {
console.error('Dry-run aborted write. Re-run with --execute to apply.');
} else throw e;
} Prevention
- Always pass --execute in scripts that intentionally write
- Use flag-less invocations deliberately as previews/dry-runs
- Keep kwargs builders passing execute: true for programmatic calls
- Make CI templates include --execute explicitly, not via concatenation
When it happens
Trigger: Running any Zhihu write command (post/answer/pin creation etc.) without passing the --execute flag; automation scripts that dropped the flag; calling the command programmatically with kwargs lacking execute:true.
Common situations: First-time users expecting the command to just run; CI pipelines where the flag was lost in argument quoting; wrappers that rebuild kwargs and forget execute.
Related errors
- ${label} must be a non-negative integer, got ${JSON.stringif
- limit must be a positive integer
- bilibili comment ${label} must be a positive integer
- bilibili comment message cannot be empty
- bilibili unfollow target cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/57190abb68ab3dcc.
Report an issue: GitHub.