{"record":{"id":"cccffd6b6e425c4a","repo":"jackwener/OpenCLI","slug":"failed-to-parse-jike-topic-data-data-message","errorCode":null,"errorMessage":"Failed to parse Jike topic data: ${data.message || 'unknown error'}","messagePattern":"Failed to parse Jike topic data: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/jike/topic.js","lineNumber":61,"sourceCode":"`);\n        if (Array.isArray(data)) {\n            if (data.length === 0) {\n                throw new EmptyResultError('jike topic', `No posts were returned for topic ${args.id}. Confirm the topic ID and login state.`);\n            }\n            return data.slice(0, limit).map((item) => ({\n                content: item.content ?? '',\n                author: item.author ?? '',\n                likes: item.likes ?? 0,\n                comments: item.comments ?? 0,\n                time: item.time ?? '',\n                url: `https://web.okjike.com/originalPost/${item.id ?? ''}`,\n            }));\n        }\n        if (data?.reason === 'missing-data-script') {\n            throw new CommandExecutionError('Jike topic page did not expose the expected data script');\n        }\n        if (data?.reason === 'parse-error') {\n            throw new CommandExecutionError(`Failed to parse Jike topic data: ${data.message || 'unknown error'}`);\n        }\n        throw new CommandExecutionError('Jike topic returned an unreadable payload');\n    },\n});\n","sourceCodeStart":43,"sourceCodeEnd":66,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/jike/topic.js#L43-L66","documentation":"When the embedded JSON script exists but JSON.parse of its textContent fails, the in-page script returns {reason:'parse-error', message} and the CLI wraps it in CommandExecutionError with the underlying parse message. This indicates the page's data blob is present but not valid JSON in the expected structure.","triggerScenarios":"JSON.parse throws inside the evaluate — the script tag contains truncated, HTML-escaped, or non-JSON content (e.g. an error page rendered into the same tag, or an encoding issue).","commonSituations":"CDN/edge serving a corrupted or partial response; Jike embedding a different payload shape into the same script tag after a front-end update; charset/escaping mismatches in the served HTML.","solutions":["Reload the page and retry — corrupted payloads are often transient.","Re-login and retry in case the served content differs by auth state.","Update the CLI/package to match a new Jike data format.","Capture data.message in the error for the exact JSON.parse failure and inspect the raw script tag in a browser."],"exampleFix":"// before\nconst data = JSON.parse(el.textContent || '{}');\n// after: tolerate partial content and log the snippet\nlet data;\ntry {\n  data = JSON.parse(el.textContent || '{}');\n} catch (e) {\n  console.error('script head:', (el.textContent || '').slice(0, 200));\n  throw e;\n}","handlingStrategy":"retry","validationCode":"// quick preflight that the script tag holds parseable JSON\nconst ok = await page.evaluate(() => {\n  const el = document.querySelector('script[type=\"application/json\"]');\n  if (!el) return false;\n  try { JSON.parse(el.textContent || '{}'); return true; } catch { return false; }\n});\nif (!ok) await page.reload();","typeGuard":null,"tryCatchPattern":"try {\n  return await runCli(['jike', 'topic', id]);\n} catch (e) {\n  if (/Failed to parse Jike topic data/.test(e.message) && attempt < 3) { await sleep(1000); return retry(); }\n  throw e;\n}","preventionTips":["Reload on first failure — corrupted payloads are often transient.","Record data.message from the error to pinpoint the JSON.parse cause.","Update the scraper if Jike changed what goes into the script tag."],"tags":["scraping","json","jike"],"backgroundTag":"json-parse-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}