{"record":{"id":"4f0b0f2c86f06bf4","repo":"jackwener/OpenCLI","slug":"command-exec-4f0b0f","errorCode":"COMMAND_EXEC","errorMessage":"${apiResult?.message || 'Failed to create comment'}","messagePattern":"\\$\\{apiResult\\?\\.message \\|\\| 'Failed to create comment'\\}","errorType":"error_code","errorClass":"CliError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/comment.js","lineNumber":48,"sourceCode":"        const apiResult = await page.evaluate(`(async () => {\n            var targetKind = ${JSON.stringify(target.kind)};\n            var targetId = ${JSON.stringify(target.id)};\n            var content = ${JSON.stringify(payload)};\n            var resourceType = targetKind === 'answer' ? 'answers' : 'articles';\n            var url = 'https://www.zhihu.com/api/v4/' + resourceType + '/' + targetId + '/comments';\n            var resp = await fetch(url, {\n                method: 'POST',\n                credentials: 'include',\n                headers: { 'Content-Type': 'application/json' },\n                body: JSON.stringify({ content: content }),\n            });\n            var data = await resp.json();\n            if (!resp.ok) return { ok: false, status: resp.status, message: data.error ? data.error.message : 'unknown error' };\n            if (!data || !data.id) return { ok: false, status: resp.status, message: 'Comment API response did not include a created comment id' };\n            return { ok: true, id: data.id, url: data.url };\n        })()`);\n        if (!apiResult?.ok) {\n            throw new CliError('COMMAND_EXEC', apiResult?.message || 'Failed to create comment');\n        }\n        return buildResultRow(`Commented on ${target.kind} ${target.id}`, target.kind, rawTarget, 'created', {\n            author_identity: authorIdentity,\n            created_url: apiResult.url || '',\n        });\n    },\n});\n","sourceCodeStart":30,"sourceCodeEnd":56,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/comment.js#L30-L56","documentation":"After submitting the comment through Zhihu's API inside the page context, the CLI wraps any non-ok result in CliError('COMMAND_EXEC', ...), surfacing the API's error message (or 'Failed to create comment' if none). The in-page call already extracts resp.error.message or detects a missing created comment id, so this error is the normalized failure of the comment-create API itself.","triggerScenarios":"The Zhihu comment API returns a non-2xx status (e.g. 401 for expired auth, 403 for banned/rate-limited, 429), or returns 200 with a body lacking data.id/data.url; the in-page promise resolves with { ok:false } and the CLI throws.","commonSituations":"Posting a comment while not logged in or after session expiry; hitting Zhihu's anti-spam/rate limiting after repeated comments; commenting on a closed or restricted answer/article; Zhihu changing the response schema so `data.id` is absent.","solutions":["Read the embedded message: if it indicates auth (401/403), re-login to zhihu.com in the browser session and retry.","Wait and retry if the message suggests rate limiting/anti-spam (429); reduce comment frequency.","Verify the target answer/article still accepts comments (not closed or restricted).","If the message is 'unknown error' or the id-missing variant, capture resp.status and inspect the API response for a Zhihu schema change and update the in-page parsing."],"exampleFix":"// before: unhandled\ncatch (e) { console.error(e.message); }\n// after: branch on the normalized error\ntry {\n  await zhihuComment(page, kwargs);\n} catch (e) {\n  if (e.code === 'COMMAND_EXEC' && /401|403|log ?in/i.test(e.message)) {\n    console.error('Zhihu auth needed — log in and retry');\n  } else throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (!execute) return { status: 'dry-run' }; // requireExecute guard; also pre-check auth with zhihu me","typeGuard":"function isApiOk(r) { return r != null && r.ok === true && typeof r.id === 'string'; }","tryCatchPattern":"try {\n  await zhihuComment(page, kwargs);\n} catch (e) {\n  if (e.code === 'COMMAND_EXEC') {\n    if (/401|403|login/i.test(e.message)) return reloginAndRetry();\n    if (/429|frequen|rate/i.test(e.message)) return backoffAndRetry();\n  }\n  throw e;\n}","preventionTips":["Confirm an active zhihu.com login before write commands.","Throttle comment submissions to avoid anti-spam/429 responses.","Log resp.status and the API message on failure to distinguish auth vs rate-limit vs closed targets."],"tags":["zhihu","api-error","write-command","rate-limit"],"backgroundTag":"upstream-api-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}