{"record":{"id":"f79743cb8e2a026c","repo":"jackwener/OpenCLI","slug":"minimax-music-returned-malformed-json-error-me","errorCode":null,"errorMessage":"MiniMax music returned malformed JSON: ${error?.message ?? error}","messagePattern":"MiniMax music returned malformed JSON: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/minimax/utils.js","lineNumber":78,"sourceCode":"            throw new TimeoutError('MiniMax music generation', timeoutSeconds, 'The request may have been accepted; result and billing state are unknown. The API exposes no task id to resume, so check account history before submitting again.');\n        }\n        throw new CommandExecutionError(\n            `MiniMax music request failed: ${error?.message ?? error}`,\n            `Check that ${region.host} is reachable. The request may have reached MiniMax; check account history before retrying.`,\n        );\n    } finally {\n        clearTimeout(timer);\n    }\n    if (response.status === 401 || response.status === 403) {\n        throw new AuthRequiredError(region.host, `MiniMax ${region.host} rejected ${MINIMAX_API_KEY_VAR} (HTTP ${response.status}).`);\n    }\n    if (!response.ok) {\n        throw new CommandExecutionError(`MiniMax music returned HTTP ${response.status} from ${region.host}`);\n    }\n    try {\n        return await response.json();\n    } catch (error) {\n        throw new CommandExecutionError(`MiniMax music returned malformed JSON: ${error?.message ?? error}`);\n    }\n}\n\nexport function parseCompletedMusic(payload, region) {\n    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {\n        throw new CommandExecutionError('MiniMax music returned a malformed response envelope');\n    }\n    const base = payload.base_resp;\n    if (!base || typeof base !== 'object' || !Number.isInteger(base.status_code)) {\n        throw new CommandExecutionError('MiniMax music response is missing integer base_resp.status_code');\n    }\n    if (base.status_code !== 0) {\n        const message = typeof base.status_msg === 'string' && base.status_msg.trim()\n            ? `: ${base.status_msg.trim()}`\n            : '';\n        if (AUTH_CODES.has(base.status_code)) {\n            throw new AuthRequiredError(region.host, `MiniMax ${region.host} rejected ${MINIMAX_API_KEY_VAR} (service ${base.status_code}${message}).`);\n        }","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/minimax/utils.js#L60-L96","documentation":"A CommandExecutionError thrown by generateMusic() when response.json() rejects — the endpoint returned an HTTP 2xx response whose body is not valid JSON (or the body was already consumed). The library treats this as a protocol violation: a successful music generation response must always be JSON with a base_resp envelope.","triggerScenarios":"await response.json() throws inside generateMusic()'s try/catch after a 2xx status — truncated/garbled response body, an HTML error page from a proxy/CDN served with 200, empty body, or mismatched content-type causing a JSON parse failure.","commonSituations":"Transparent proxies or captive portals injecting HTML with 200; TLS-intercepting appliances; body truncation on flaky mobile networks; pointing the endpoint at a wrong/gateway URL in a modified region config.","solutions":["Capture the raw response body (e.g. curl the endpoint with your key) to see what non-JSON content is actually returned.","Disable or bypass any TLS-intercepting proxy/antivirus that may rewrite the response, then retry.","Retry on a stable network; truncated bodies are usually transient transport problems.","Verify region.endpoint was not overridden to a non-MiniMax URL (check MUSIC_REGIONS config)."],"exampleFix":"// diagnose outside the CLI\ncurl -s -H \"authorization: Bearer $MINIMAX_API_KEY\" \\\n  -H 'content-type: application/json' \\\n  -d '{...}' https://api.minimax.io/v1/music_generation | head -c 500\n\n// if HTML appears, fix the proxy or use a direct connection instead of retrying blind","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const payload = await generateMusic(region, apiKey, body, 60);\n} catch (e) {\n  if (e instanceof CommandExecutionError && /malformed JSON/.test(e.message)) {\n    // bypass suspect proxy, verify endpoint URL, then retry once\n  } else throw e;\n}","preventionTips":["Avoid TLS-intercepting proxies/antivirus for API traffic.","Confirm the endpoint host is the official MiniMax domain.","Retry transient truncations on stable networks.","Capture raw bodies when diagnosing instead of assuming JSON."],"tags":["json","parse","protocol","network"],"backgroundTag":"invalid-json-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}