{"record":{"id":"ef5666b0d4048072","repo":"chenhg5/cc-connect","slug":"mimo-tts-marshal-request-w","errorCode":null,"errorMessage":"mimo tts: marshal request: %w","messagePattern":"mimo tts: marshal request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/tts.go","lineNumber":470,"sourceCode":"\n\t// Per MiMo docs: synthesis text MUST live on an assistant message; the\n\t// user message is optional for built-in-voice mode but required for\n\t// voicedesign. Sending an empty user content stays valid across all\n\t// three model variants.\n\treqBody := map[string]any{\n\t\t\"model\": m.Model,\n\t\t\"messages\": []map[string]any{\n\t\t\t{\"role\": \"user\", \"content\": \"\"},\n\t\t\t{\"role\": \"assistant\", \"content\": text},\n\t\t},\n\t\t\"audio\": map[string]any{\n\t\t\t\"format\": \"wav\",\n\t\t\t\"voice\":  voice,\n\t\t},\n\t}\n\tjsonData, err := json.Marshal(reqBody)\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"mimo tts: marshal request: %w\", err)\n\t}\n\n\turl := strings.TrimRight(m.BaseURL, \"/\") + \"/chat/completions\"\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(jsonData))\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"mimo tts: create request: %w\", err)\n\t}\n\t// MiMo authenticates via \"api-key\" header, not \"Authorization: Bearer\".\n\treq.Header.Set(\"api-key\", 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(\"mimo tts: request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tbody, err := io.ReadAll(resp.Body)","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/tts.go#L452-L488","documentation":"This error wraps json.Marshal failing while encoding the MiMo (Xiaomi MiMo-V2.5-TTS) request body inside Synthesize. Marshaling a plain map[string]any of strings/bools essentially cannot fail in practice, so hitting this indicates corrupted inputs (e.g. strings containing invalid content is not possible for JSON, but unsupported types or a canceled context via custom marshalers would). Practically it signals an internal/programming error building the payload.","triggerScenarios":"A value in the request map implements json.Marshaler and returns an error; unsupported type (chan, func, complex) placed in the options map — only possible if the payload construction changes; effectively never with the current literal map.","commonSituations":"Rare; mostly seen if someone modifies the request body construction to inject dynamic values (e.g. non-string options from config) that aren't JSON-serializable.","solutions":["Inspect the wrapped %w error to identify which value failed to marshal.","Ensure only JSON-serializable types (string, bool, number) are put into the request map.","If injecting config-derived values, coerce them to strings/float64 before adding to the payload.","Treat as a bug report if reproducible with the stock code path."],"exampleFix":"// before\nopts := map[string]any{\"format\": \"wav\", \"voice\": voice, \"extra\": someUnsupportedValue}\n// after\nopts := map[string]any{\"format\": \"wav\", \"voice\": voice} // only JSON-serializable values","handlingStrategy":"try-catch","validationCode":"// ensure payload values are JSON-encodable\nif _, err := json.Marshal(reqBody); err != nil { return fmt.Errorf(\"invalid tts payload: %w\", err) }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"marshal request\") {\n    // programming bug in payload construction — log and report\n}","preventionTips":["Keep request bodies to plain string/bool/number literals","If injecting dynamic config values, coerce to JSON-safe types first","Add a unit test that marshals the built request body"],"tags":["go","json","serialization","tts","mimo"],"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-14T05:17:10.506Z"}