{"record":{"id":"57190abb68ab3dcc","repo":"jackwener/OpenCLI","slug":"invalid-input-57190a","errorCode":"INVALID_INPUT","errorMessage":"INVALID_INPUT","messagePattern":"INVALID_INPUT","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/write-shared.js","lineNumber":94,"sourceCode":"    for (const root of roots) {\n        for (const node of Array.from(root.querySelectorAll(PROFILE_LINK_SELECTOR)).filter(isIdentityNodeLike)) {\n            const slug = getSlugFromIdentityLink(node, allowAvatarOnly);\n            if (slug)\n                return slug;\n        }\n    }\n    return null;\n}\nexport function resolveCurrentUserSlugFromDom(state, documentRoot) {\n    const slugFromState = resolveSlugFromState(state);\n    if (slugFromState)\n        return slugFromState;\n    const navScopes = Array.from(documentRoot.querySelectorAll(NAV_SCOPE_SELECTOR)).filter(isIdentityRootLike);\n    return findCurrentUserSlugFromRoots(navScopes, true) || findCurrentUserSlugFromRoots([documentRoot], false);\n}\nexport function requireExecute(kwargs) {\n    if (!kwargs.execute) {\n        throw new CliError('INVALID_INPUT', 'This Zhihu write command requires --execute');\n    }\n}\nexport async function resolvePayload(kwargs, deps = defaultFileReaderDeps()) {\n    const text = typeof kwargs.text === 'string' ? kwargs.text : undefined;\n    const file = typeof kwargs.file === 'string' ? kwargs.file : undefined;\n    if (text && file) {\n        throw new CliError('INVALID_INPUT', 'Use either <text> or --file, not both');\n    }\n    let resolved = text ?? '';\n    if (file) {\n        let fileStat;\n        try {\n            fileStat = await deps.stat(file);\n        }\n        catch {\n            throw new CliError('INVALID_INPUT', `File not found: ${file}`);\n        }\n        if (!fileStat.isFile()) {","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/write-shared.js#L76-L112","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nnode cli.js zhihu write-answer --text 'hello'\n// after\nnode cli.js zhihu write-answer --text 'hello' --execute","handlingStrategy":"validation","validationCode":"// in wrapper scripts, assert the flag before invoking\nif (!process.argv.includes('--execute')) {\n  console.error('Refusing to run: --execute is required for Zhihu write commands');\n  process.exit(2);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runZhihuWrite(args);\n} catch (e) {\n  if (e.code === 'INVALID_INPUT' && /--execute/.test(e.message)) {\n    console.error('Dry-run aborted write. Re-run with --execute to apply.');\n  } else throw e;\n}","preventionTips":["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"],"tags":["cli","input-validation","flags"],"backgroundTag":"missing-required-flag","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}