jackwener/OpenCLI · error · Error

帖子访问失败: ${errorInfo.message} (code: ${errorInfo.code})

Error message

帖子访问失败: ${errorInfo.message} (code: ${errorInfo.code})

What it means

When reading a Hupu thread detail, the library parses the page's __NEXT_DATA__ payload via readHupuNextData. If the embedded detail_error_info has a code other than 200, the server-side fetch of the thread failed and the library surfaces that code and message as a plain Error.

Source

Thrown at clis/hupu/detail.js:35

        },
        {
            name: 'replies',
            type: 'boolean',
            default: false,
            help: '是否包含热门回复'
        }
    ],
    columns: ['title', 'author', 'content', 'replies', 'lights', 'url'],
    func: async (page, kwargs) => {
        const { tid, replies: includeReplies = false } = kwargs;
        const url = getHupuThreadUrl(tid).replace(/-1\.html$/, '.html');
        const data = await readHupuNextData(page, url, 'Read Hupu thread detail', {
            expectedTid: String(tid),
        });
        // 检查错误信息(只有当code不是200时才报错)
        const errorInfo = data.props.pageProps.detail_error_info;
        if (errorInfo && errorInfo.code !== 200) {
            throw new Error(`帖子访问失败: ${errorInfo.message} (code: ${errorInfo.code})`);
        }
        // 获取帖子信息
        const thread = data.props.pageProps.detail?.thread;
        if (!thread) {
            throw new Error('帖子不存在或已被删除');
        }
        const authorName = thread.author?.puname || '未知作者';
        const content = stripHtml(thread.content);
        const contentPreview = content.length > 300 ? content.substring(0, 300) + '...' : content;
        // 构建结果
        const result = {
            title: thread.title,
            author: authorName,
            content: contentPreview,
            replies: thread.replies || 0,
            lights: thread.lights || 0,
            url: `https://bbs.hupu.com/${tid}.html`
        };

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Verify the tid/URL is correct and the thread opens in a normal browser
  2. Retry later if Hupu is having backend issues (code often transient)
  3. Treat codes like 404/403 as 'thread unavailable' and handle gracefully in your script
  4. If valid threads consistently fail, Hupu's __NEXT_DATA__ schema likely changed — update readHupuNextData parsing

Example fix

// before
const detail = await hupuDetail(tid);
// after
let detail;
try { detail = await hupuDetail(tid); }
catch (e) {
  if (/code: 404/.test(e.message)) return null; // thread gone
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

const res = await fetch(threadUrl, { method: 'HEAD' });
if (!res.ok) skipThread(tid);

Type guard

function isThreadAvailable(nextData) {
  const info = nextData?.props?.pageProps?.detail_error_info;
  return !info || info.code === 200;
}

Try / catch

try {
  const d = await hupuDetail(tid);
} catch (e) {
  const code = e.message.match(/code: (\d+)/)?.[1];
  if (code === '404' || code === '403') return null; // treat as unavailable
  throw e;
}

Prevention

When it happens

Trigger: Fetching a thread (by tid) whose __NEXT_DATA__ contains detail_error_info.code !== 200 — e.g. the thread was removed by moderators, requires permissions, or Hupu's backend returned an error for that tid.

Common situations: Deleted or shadow-removed posts still indexed by search engines; region/permission-restricted threads; Hupu API degradation returning non-200 codes for valid threads; mistyped tid pointing at a nonexistent post.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/11d6f8b286606e6f. Report an issue: GitHub.