{"record":{"id":"738fe5e83bdc29b2","repo":"jackwener/OpenCLI","slug":"label-failed-detail","errorCode":null,"errorMessage":"${label} failed: ${detail}","messagePattern":"(.+?) failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/nowcoder/posts.js","lineNumber":249,"sourceCode":"\nexport function requirePositiveInt(value, name, maximum) {\n    const number = Number(value);\n    if (!Number.isInteger(number) || number < 1 || number > maximum) throw new ArgumentError(`nowcoder --${name} must be an integer from 1 to ${maximum}`);\n    return number;\n}\n\nexport async function fetchNowcoderData(page, url, options, label) {\n    let payload;\n    try {\n        await page.goto('https://www.nowcoder.com');\n        payload = await page.fetchJson(url, options);\n    }\n    catch (error) {\n        const detail = String(error?.message ?? error);\n        if (/HTTP\\s+(401|403)|need login|not logged in/i.test(detail)) {\n            throw new AuthRequiredError('nowcoder.com', `${label} requires a logged-in Nowcoder session`);\n        }\n        throw new CommandExecutionError(`${label} failed: ${detail}`);\n    }\n    if (!isRecord(payload) || typeof payload.success !== 'boolean' || !Number.isSafeInteger(payload.code)) throw new CommandExecutionError(`${label} returned a malformed envelope`);\n    const message = typeof payload.msg === 'string' ? payload.msg : 'unknown error';\n    if (!payload.success || payload.code !== 0) {\n        if (payload.code === 999 || /need login|登录/i.test(message)) {\n            throw new AuthRequiredError('nowcoder.com', `${label} requires a logged-in Nowcoder session: ${message}`);\n        }\n        throw new CommandExecutionError(`${label} failed: ${message} (${payload.code})`);\n    }\n    if (!isRecord(payload.data)) throw new CommandExecutionError(`${label} returned malformed data`);\n    return payload.data;\n}\n","sourceCodeStart":231,"sourceCodeEnd":262,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nowcoder/posts.js#L231-L262","documentation":"If the JSON request inside fetchNowcoderData throws for any reason that is NOT an auth failure (no 401/403 or login-related message), the library wraps the underlying error as CommandExecutionError with the label prefix and the original detail, e.g. 'Nowcoder posts list failed: net::ERR_CONNECTION_TIMED_OUT'. It preserves the root cause text so you can diagnose the real transport problem.","triggerScenarios":"Network timeouts, DNS failures, connection resets, TLS errors, HTTP 5xx, 404s, rate limiting (429), or anti-bot HTML responses during page.goto or page.fetchJson for a nowcoder data command.","commonSituations":"Nowcoder being slow or down; corporate proxy/firewall blocking the request; being rate-limited after rapid successive calls; transient offline network; antivirus/SSL interception breaking TLS.","solutions":["Read the detail suffix for the root cause (timeout, DNS, HTTP status) and address that specifically.","Retry after a delay — transient network or rate-limit issues usually clear up.","Check general connectivity to www.nowcoder.com (curl or browser) to distinguish local network issues from server issues.","If rate-limited, slow down request frequency or add delays between calls.","Verify proxy/VPN/firewall settings if the failure is persistent for nowcoder.com only."],"exampleFix":"// before\nfor (const id of ids) await getPost(id);  // rapid loop -> rate limited\n// after\nfor (const id of ids) { await getPost(id); await sleep(2000); }","handlingStrategy":"retry","validationCode":"// pre-flight connectivity check\nconst ok = await fetch('https://www.nowcoder.com', { method: 'HEAD' }).then(r => r.ok).catch(() => false);\nif (!ok) throw new Error('nowcoder.com unreachable; fix network/proxy before running');","typeGuard":null,"tryCatchPattern":"async function withRetry(fn, attempts = 3) {\n  for (let i = 0; i < attempts; i++) {\n    try { return await fn(); }\n    catch (err) {\n      if (err instanceof AuthRequiredError || i === attempts - 1) throw err;\n      await new Promise(r => setTimeout(r, 2000 * 2 ** i));\n    }\n  }\n}\n// withRetry(() => nowcoderPostsList(opts));","preventionTips":["Add exponential backoff and jitter around all nowcoder fetches.","Throttle request rate to avoid rate limits and anti-bot responses.","Check proxy/VPN/firewall settings when failures are persistent.","Parse the 'failed: <detail>' suffix to route timeouts, DNS, and 5xx differently."],"tags":["network","http-error","request-failed"],"backgroundTag":"http-request-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}