{"record":{"id":"54caecbf7983865e","repo":"jackwener/OpenCLI","slug":"label-returned-malformed-json-err-message-54caec","errorCode":null,"errorMessage":"${label} returned malformed JSON: ${err?.message ?? err}","messagePattern":"(.+?) returned malformed JSON: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/nuget/utils.js","lineNumber":73,"sourceCode":"            `${label} request failed: ${err?.message ?? err}`,\n            'Check that api.nuget.org is reachable from this network.',\n        );\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `NuGet returned 404 for ${url}.`);\n    }\n    if (resp.status === 429) {\n        throw new CommandExecutionError(`${label} returned HTTP 429 (rate limited)`);\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\nexport function joinTags(tags) {\n    if (!Array.isArray(tags)) return '';\n    return tags.filter((t) => typeof t === 'string' && t.trim()).join(', ');\n}\n\nexport function joinAuthors(authors) {\n    if (Array.isArray(authors)) return authors.filter((a) => typeof a === 'string' && a.trim()).join(', ');\n    if (typeof authors === 'string') return authors.trim();\n    return '';\n}\n","sourceCodeStart":55,"sourceCodeEnd":88,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nuget/utils.js#L55-L88","documentation":"This CommandExecutionError is thrown by nugetFetch in clis/nuget/utils.js when resp.json() fails — the server returned an HTTP-ok response whose body is not valid JSON (or the connection was truncated mid-body). The library expects all NuGet endpoints to return JSON (it sends accept: application/json) so a non-JSON body indicates an intercepted or malformed response.","triggerScenarios":"A proxy or captive portal returning an HTML login/error page with status 200; TLS-intercepting middleboxes rewriting responses; truncated response bodies on flaky networks; a CDN edge returning an HTML error page.","commonSituations":"Hotel/airport Wi-Fi captive portals; corporate SSL inspection appliances; very large search responses cut off by an aggressive proxy timeout.","solutions":["Inspect the raw response (curl the URL) to see what body is actually returned","Bypass or reconfigure the intercepting proxy / complete captive-portal login","Retry the request — truncation is often transient","Check NODE_EXTRA_CA_CERTS / TLS setup if a corporate appliance is rewriting traffic"],"exampleFix":"// before\nconst data = await nugetFetch(url, 'search'); // throws on HTML body\n// after\ntry {\n  const data = await nugetFetch(url, 'search');\n} catch (e) {\n  if (String(e.message).includes('malformed JSON')) {\n    // fall back or retry — likely proxy/captive portal\n  }\n  throw e;\n}","handlingStrategy":"fallback","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  const data = await nugetFetch(url, 'search');\n} catch (e) {\n  if (e instanceof CommandExecutionError && e.message.includes('malformed JSON')) {\n    await sleep(1000);\n    return nugetFetch(url, 'search'); // truncated/proxied response; retry\n  }\n  throw e;\n}","preventionTips":["Complete captive-portal logins before running network scripts","Bypass SSL-inspection proxies for *.nuget.org or trust their CA via NODE_EXTRA_CA_CERTS","Retry on malformed JSON — truncation is often transient","Inspect raw responses with curl when it recurs consistently"],"tags":["http","json","parsing","network","nuget"],"backgroundTag":"invalid-json-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}