{"record":{"id":"0f5b32fd61ebfc63","repo":"jackwener/OpenCLI","slug":"label-returned-malformed-json-err-message","errorCode":null,"errorMessage":"${label} returned malformed JSON: ${err?.message ?? err}","messagePattern":"(.+?) returned malformed JSON: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/crates/utils.js","lineNumber":69,"sourceCode":"    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `crates.io returned 404 for ${url}.`);\n    }\n    if (resp.status === 429) {\n        throw new CommandExecutionError(\n            `${label} returned HTTP 429 (rate limited)`,\n            'crates.io rate-limits unauthenticated traffic; 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":51,"sourceCodeEnd":73,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/crates/utils.js#L51-L73","documentation":"After a successful HTTP response, cratesFetch parses the body with resp.json(); if that throws, it raises `\"${label} returned malformed JSON: ...\"` as a CommandExecutionError. This means the endpoint responded with a 2xx but the payload was not valid JSON (or was truncated), so the response could be a proxy error page, HTML, or a partial body.","triggerScenarios":"cratesFetch receives an OK response whose body fails JSON.parse: an intercepting proxy/captive portal returning HTML, a truncated response, or a changed endpoint returning a non-JSON format.","commonSituations":"Corporate proxies or antivirus rewriting responses; hotel/airport Wi-Fi captive portals; very large responses cut off by a middlebox; crates.io serving an HTML error page with 200.","solutions":["Check what the endpoint actually returns: `curl -i <url>` and inspect the raw body for HTML/proxy text.","Disable or bypass any intercepting proxy/VPN/captive portal and retry.","Retry the command — truncation from transient network issues is common.","If it persists on a specific endpoint, report it; the adapter may need to track a crates.io API format change."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const data = await opencli.crates.info(name);\n} catch (err) {\n  if (err.message.includes('malformed JSON')) {\n    // bypass proxy / retry once after short delay\n  }\n  throw err;\n}","preventionTips":["Run `curl -i <crates.io url>` when on suspicious networks to spot HTML/proxy responses.","Avoid captive portals and intercepting proxies for API traffic.","Retry on flaky networks; truncation is usually transient.","Keep TLS inspection exceptions for crates.io in corporate environments."],"tags":["json","malformed-response","crates-io","network"],"backgroundTag":"invalid-json-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}