{"record":{"id":"6cacf54c74a30029","repo":"chenhg5/cc-connect","slug":"minimax-tts-marshal-request-w","errorCode":null,"errorMessage":"minimax tts: marshal request: %w","messagePattern":"minimax tts: marshal request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/tts.go","lineNumber":330,"sourceCode":"\t\tspeed = 1.0\n\t}\n\n\treqBody := map[string]any{\n\t\t\"model\":  m.Model,\n\t\t\"text\":   text,\n\t\t\"stream\": true,\n\t\t\"voice_setting\": map[string]any{\n\t\t\t\"voice_id\": voice,\n\t\t\t\"speed\":    speed,\n\t\t},\n\t\t\"audio_setting\": map[string]any{\n\t\t\t\"format\":      \"mp3\",\n\t\t\t\"sample_rate\": 32000,\n\t\t},\n\t}\n\tjsonData, err := json.Marshal(reqBody)\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"minimax tts: marshal request: %w\", err)\n\t}\n\n\turl := strings.TrimRight(m.BaseURL, \"/\") + \"/v1/t2a_v2\"\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(jsonData))\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"minimax tts: create request: %w\", err)\n\t}\n\treq.Header.Set(\"Authorization\", \"Bearer \"+m.APIKey)\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\n\tresp, err := m.Client.Do(req)\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"minimax tts: request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tbody, _ := io.ReadAll(resp.Body)","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/tts.go#L312-L348","documentation":"This error is returned by the MiniMax TTS Synthesize method when json.Marshal fails to serialize the T2A v2 request body. Since the request body is built from a map[string]any of plain strings/numbers, this failure is extremely rare and would indicate a programmer error or a non-marshalable value injected into the request map rather than a runtime/user problem.","triggerScenarios":"Only if the request body map contains a value json.Marshal cannot encode (e.g. a channel, func, or cyclic value placed into reqBody after a code change). The current hardcoded map cannot trigger it.","commonSituations":"Essentially never seen in production; encountered only after custom modifications that inject dynamic values (e.g. plugin-supplied voice params) into the request body.","solutions":["Audit any modified code that adds values to the reqBody map for non-JSON-serializable types","Convert dynamic values to JSON-safe types (string, float64, bool, nested maps) before adding them","If marshaling complex options, use typed structs with json tags instead of map[string]any"],"exampleFix":"// before\nreqBody[\"voice_modifier\"] = someFunc // not marshalable\n// after\nreqBody[\"voice_modifier\"] = someFuncName // string value","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"mp3, format, err := tts.Synthesize(ctx, text)\nif err != nil {\n    if strings.Contains(err.Error(), \"minimax tts: marshal request\") {\n        // non-serializable value in request body; audit custom modifications\n    }\n    return err\n}","preventionTips":["Use typed request structs with json tags instead of map[string]any","Never inject funcs, channels, or cyclic data into request maps","Add a unit test that marshals the exact request body construction"],"tags":["go","tts","json","marshal"],"backgroundTag":"json-marshal-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}