{"record":{"id":"803d1babbb87357d","repo":"jackwener/OpenCLI","slug":"label-returned-malformed-json-err-message-803d1b","errorCode":null,"errorMessage":"${label} returned malformed JSON: ${err?.message ?? err}","messagePattern":"(.+?) returned malformed JSON: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/dblp/utils.js","lineNumber":62,"sourceCode":"        if (res.status === 429) {\n            throw new CommandExecutionError(`${label} returned HTTP 429 (rate limited)`, 'dblp throttles clients that fetch too aggressively. Wait a few seconds and retry, or lower --limit.');\n        }\n        if (res.status === 404) {\n            throw new EmptyResultError(label, 'dblp returned 404 — the requested record may not exist.');\n        }\n        throw new CommandExecutionError(`${label} returned HTTP ${res.status}`, 'Inspect the response in a browser at the same URL for more context.');\n    }\n    return res;\n}\n\nexport async function dblpFetchJson(path, label) {\n    const res = await dblpFetch(`${DBLP_ORIGIN}${path}`, label, 'application/json');\n    let body;\n    try {\n        body = await res.json();\n    }\n    catch (err) {\n        throw new CommandExecutionError(`${label} returned malformed JSON: ${err?.message ?? err}`);\n    }\n    const statusCode = String(body?.result?.status?.['@code'] ?? '').trim();\n    if (!statusCode) {\n        throw new CommandExecutionError(\n            `${label} returned JSON without result.status.@code`,\n            'dblp changed its JSON envelope or returned a partial error payload; inspect the raw response in a browser.',\n        );\n    }\n    if (statusCode !== '200') {\n        const statusText = String(body?.result?.status?.text ?? '').trim();\n        throw new CommandExecutionError(\n            `${label} returned API status ${statusCode}${statusText ? ` (${statusText})` : ''}`,\n            'dblp accepted the HTTP request but reported an API-level failure. Retry later or inspect the same query in a browser.',\n        );\n    }\n    return body;\n}\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/dblp/utils.js#L44-L80","documentation":"dblpFetchJson calls res.json() and this error is thrown when the response body cannot be parsed as JSON. It means dblp returned an HTTP 2xx response whose body is not valid JSON (e.g. an HTML error page or truncated response). The underlying parse error message is included.","triggerScenarios":"dblpFetch succeeded (res.ok) but res.json() throws — the body is HTML (error/interstitial page), empty, or truncated mid-stream.","commonSituations":"A proxy or captive portal injecting an HTML page with a 200 status; dblp serving a maintenance/interstitial page; network interruption truncating the response; hitting an HTML endpoint by mistake.","solutions":["Retry the request — truncated/bodies and transient interstitials often resolve on retry","Open the same URL in a browser to see what body dblp actually returns","Check for a proxy/captive portal that could inject HTML into 200 responses","If persistent, verify the path/format= parameters produce a JSON API endpoint"],"exampleFix":"// before\nconst body = await res.json(); // throws on HTML body\n// after\nconst text = await res.text();\nlet body;\ntry { body = JSON.parse(text); }\ncatch { console.error('Non-JSON body:', text.slice(0, 200)); }","handlingStrategy":"try-catch","validationCode":"const res = await fetch(url);\nconst text = await res.text();\nif (!text.trim().startsWith('{') && !text.trim().startsWith('[')) {\n  console.warn('Non-JSON body received:', text.slice(0, 120));\n}","typeGuard":"function isJsonObject(v) { return v !== null && typeof v === 'object' && !Array.isArray(v); }","tryCatchPattern":"try {\n  const json = await dblpFetchJson(path, 'dblp search');\n} catch (err) {\n  if (/malformed JSON/.test(err.message)) {\n    // log/inspect the raw body, then retry once for truncated responses\n    return retryFetch(path);\n  }\n  throw err;\n}","preventionTips":["Check for proxies/captive portals that inject HTML into responses","Read the body as text and preview it before JSON.parse when debugging","Retry truncated responses once before failing","Pin requests to the documented /api?format=json endpoints"],"tags":["json","parsing","network","dblp"],"backgroundTag":"malformed-json-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}