{"record":{"id":"0945637673498f06","repo":"jackwener/OpenCLI","slug":"minimax-music-returned-a-malformed-response-envelo","errorCode":null,"errorMessage":"MiniMax music returned a malformed response envelope","messagePattern":"MiniMax music returned a malformed response envelope","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/minimax/utils.js","lineNumber":84,"sourceCode":"    } 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        }\n        throw new CommandExecutionError(`MiniMax music failed (service ${base.status_code}${message})`);\n    }\n    const data = payload.data;\n    if (!data || typeof data !== 'object' || Array.isArray(data) || !Number.isInteger(data.status)) {\n        throw new CommandExecutionError('MiniMax music response is missing integer data.status');\n    }","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/minimax/utils.js#L66-L102","documentation":"A CommandExecutionError thrown by parseCompletedMusic() when the parsed JSON body is not a plain object — null, an array, or a non-object. MiniMax music responses must follow the {base_resp: {...}} envelope, so anything else cannot be interpreted as a generation result.","triggerScenarios":"parseCompletedMusic(payload) is called (via the completed step) with a payload that is null, undefined, an Array, or a primitive — e.g. the endpoint returned JSON like \"ok\", [], or null with HTTP 200, and that body was passed straight through.","commonSituations":"MiniMax changing or versioning their response schema; a gateway returning a bare JSON literal with 200; mocking/stubbing in tests that supplies the wrong envelope shape; proxy middleware rewriting bodies.","solutions":["Log the raw HTTP body before parsing to confirm what MiniMax actually returned.","Retry the generation — a one-off gateway artifact often resolves on resubmission (check account history first to avoid double billing).","Check MiniMax API changelog/docs for envelope changes if this recurs systematically.","If you feed parseCompletedMusic manually (tests, scripts), pass the full response object, not a sub-field."],"exampleFix":"// before\ndone(payload.data); // wrong: sub-object, envelope lost\n\n// after\ndone(payload); // pass the full {base_resp, data} envelope","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isMusicEnvelope(v) {\n  return v != null && typeof v === 'object' && !Array.isArray(v);\n}\n// guard before parsing\nif (!isMusicEnvelope(raw)) throw new Error('Unexpected non-object MiniMax response');","tryCatchPattern":"try {\n  const done = parseCompletedMusic(payload, region);\n} catch (e) {\n  if (e instanceof CommandExecutionError && /malformed response envelope/.test(e.message)) {\n    // log raw body, then retry the generation once\n  } else throw e;\n}","preventionTips":["Always pass the full parsed response object to parseCompletedMusic, never a sub-field.","Keep fixtures in tests shaped like real MiniMax envelopes.","Watch MiniMax changelogs for envelope schema changes."],"tags":["schema-validation","response-parsing","api-change"],"backgroundTag":"schema-validation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}