{"record":{"id":"a6c9f46bf58f613a","repo":"jackwener/OpenCLI","slug":"errormessage-a6c9f4","errorCode":null,"errorMessage":"回复失败: ${errorMessage}","messagePattern":"回复失败: \\$\\{errorMessage\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/hupu/reply.js","lineNumber":69,"sourceCode":"            body.quoteId = quote_id;\n        }\n        try {\n            const result = await postHupuJson(page, tid, url, body, 'Reply to Hupu thread', 'reply');\n            if (result.code === 1) {\n                return [{\n                        status: '✅ 回复成功',\n                        message: result.msg || result.message || ''\n                    }];\n            }\n            else {\n                throw new Error(`接口错误 code=${result.code}: ${result.msg || result.message}`);\n            }\n        }\n        catch (error) {\n            if (error instanceof CliError)\n                throw error;\n            const errorMessage = error instanceof Error ? error.message : String(error);\n            throw new Error(`回复失败: ${errorMessage}`);\n        }\n    },\n});\n","sourceCodeStart":51,"sourceCodeEnd":73,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hupu/reply.js#L51-L73","documentation":"This is the outer catch-all wrapper in the hupu reply CLI: any error thrown during the reply flow that is not a CliError (network failure, API business error like '接口错误 code=...', JSON parse error) is re-thrown as Error('回复失败: <message>'). It guarantees a uniform Chinese-prefixed failure message but chains the original cause text.","triggerScenarios":"Any failure inside the try block of hupu reply: postHupuJson network/HTTP failure, non-1 API code thrown at line 62, or unexpected exceptions during page automation — all get prefixed with '回复失败: '.","commonSituations":"Hupu API rejecting the reply (see inner error); browser page closed or navigated mid-request; network outage; invalid cookies causing server rejection; unexpected HTML/error page instead of JSON.","solutions":["Look at the text after '回复失败: ' — it contains the underlying cause (接口错误 code=... or network error).","If it's '接口错误', follow the code/msg fixes (valid tid/topic_id, login, content policy).","If it's a network/page error, ensure the browser session is alive and retry.","Re-login to bbs.hupu.com if the cause suggests invalid authentication."],"exampleFix":"// before\ntry { await reply(...) } catch (e) { /* opaque: 回复失败: ... */ }\n// after: inspect the chained cause in your caller\ntry {\n  await runReply(tid, topicId, text);\n} catch (e) {\n  const cause = String(e.message).replace('回复失败: ', '');\n  if (cause.includes('接口错误 code=')) console.error('Hupu rejected reply:', cause);\n  else throw e; // retryable/network issue\n}","handlingStrategy":"try-catch","validationCode":"// Pre-validate all required args so the call never reaches the API malformed\nconst args = { tid: '631234567', topic_id: '502', text: 'good game' };\nif (!/^\\d{9}$/.test(args.tid) || !args.topic_id || !args.text.trim()) {\n  throw new Error('hupu reply requires 9-digit tid, matching topic_id, and non-empty text');\n}","typeGuard":"function isCliError(e) {\n  return e instanceof Error && e.name === 'CliError';\n}","tryCatchPattern":"try {\n  const out = await run('hupu reply', { _: [tid, text], topic_id });\n} catch (e) {\n  if (isCliError(e)) throw e; // structured library error, surface as-is\n  const cause = String(e.message).startsWith('回复失败: ') ? e.message.slice('回复失败: '.length) : e.message;\n  console.error('Reply failed, root cause:', cause); // then branch on 接口错误 vs network\n}","preventionTips":["Always strip the '回复失败: ' prefix to read the real root cause.","Validate tid/topic_id/text before invoking to eliminate the most common failure paths.","Keep the browser session alive and logged in during write operations.","Distinguish CliError from wrapped Error so you don't double-wrap or lose the original cause."],"tags":["hupu","error-wrapping","write-operation","try-catch"],"backgroundTag":"error-rethrow-wrapper","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}