{"record":{"id":"a0a1ed8557013145","repo":"jackwener/OpenCLI","slug":"label-returned-malformed-json-err-message-a0a1ed","errorCode":null,"errorMessage":"${label} returned malformed JSON: ${err?.message ?? err}","messagePattern":"(.+?) returned malformed JSON: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/pypi/utils.js","lineNumber":52,"sourceCode":"    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `PyPI returned 404 for ${url}.`);\n    }\n    if (resp.status === 429) {\n        throw new CommandExecutionError(\n            `${label} returned HTTP 429 (rate limited)`,\n            'PyPI throttles unauthenticated bursts; wait a few seconds and retry.',\n        );\n    }\n    if (!resp.ok) {\n        throw new CommandExecutionError(`${label} returned HTTP ${resp.status}`);\n    }\n    let body;\n    try {\n        body = await resp.json();\n    }\n    catch (err) {\n        throw new CommandExecutionError(`${label} returned malformed JSON: ${err?.message ?? err}`);\n    }\n    return body;\n}\n","sourceCodeStart":34,"sourceCodeEnd":56,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pypi/utils.js#L34-L56","documentation":"CommandExecutionError thrown by pypiFetch when resp.json() fails to parse the response body. The endpoint returned a 2xx response but the body is not valid JSON. The original parse error message is appended to help diagnose what was actually returned.","triggerScenarios":"A 200 response whose body is HTML (login/interstitial page from a proxy or captive portal), a truncated response, or a mirror returning a non-JSON error page with a success status.","commonSituations":"Corporate proxies injecting HTML into responses; airport/hotel captive portals; content-filtering middleboxes; broken custom mirrors or registries.","solutions":["curl the same URL and inspect the raw body to see what is being returned","Disable or bypass the interfering proxy/VPN","Check that no HTTPS-intercepting appliance is rewriting the response","Retry — truncation from flaky connections is often transient"],"exampleFix":"// diagnose before fixing\ncurl -s https://pypi.org/pypi/requests/json | head -c 200\n// if HTML appears, bypass proxy:\n# after (shell)\nNO_PROXY=pypi.org pypi package requests","handlingStrategy":"fallback","validationCode":"const res = await fetch(url);\nconst text = await res.text();\ntry { JSON.parse(text); } catch { console.error('Non-JSON body (proxy/portal?):', text.slice(0, 120)); }","typeGuard":"function isJsonObject(text) { try { const v = JSON.parse(text); return v !== null && typeof v === 'object'; } catch { return false; } }","tryCatchPattern":"try {\n  const pkg = await pypiPackage(name);\n} catch (e) {\n  if (/malformed JSON/i.test(e.message)) {\n    // inspect raw body / bypass proxy, then retry\n  } else throw e;\n}","preventionTips":["Check for captive portals or HTTPS-intercepting proxies on the network","curl the endpoint and inspect raw bytes when JSON errors appear","Use trusted networks or NO_PROXY overrides for pypi.org"],"tags":["pypi","json","malformed-response"],"backgroundTag":"invalid-json-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}