{"record":{"id":"8f76809541cd3588","repo":"chenhg5/cc-connect","slug":"mimo-tts-create-request-w","errorCode":null,"errorMessage":"mimo tts: create request: %w","messagePattern":"mimo tts: create request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/tts.go","lineNumber":476,"sourceCode":"\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)\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"mimo tts: read response: %w\", err)\n\t}\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, \"\", fmt.Errorf(\"mimo tts API %d: %s\", resp.StatusCode, body)\n\t}","sourceCodeStart":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/tts.go#L458-L494","documentation":"This error wraps http.NewRequestWithContext failing while building the POST to MiMo's /chat/completions TTS endpoint. As with the MiniMax equivalent, it fires only when the context is already canceled/expired, the URL is unparseable, or the method is invalid — the request never reached the network.","triggerScenarios":"ctx canceled or deadline elapsed before the call; base_url malformed (invalid scheme, spaces, control chars) making TrimRight(base)+\"/chat/completions\" unparseable.","commonSituations":"Wrong mimo base_url in config.toml (typo, missing https://, stray whitespace in the TOML string); caller passing an already-expired context; upstream timeout exhausted before TTS was invoked.","solutions":["Check ctx.Err() at the call site to confirm context cancellation, and use a fresh/longer-lived context.","Validate base_url in config.toml: absolute URL, no spaces, correct scheme, quotes trimming fine.","Add a deadline margin so the TTS call is not entered with <1s remaining on a parent deadline.","Retry with a new context if the cancellation was transient."],"exampleFix":"// before\nbase_url = \"https ://api.mimo.example.com\"   # stray space → invalid URL\n// after\nbase_url = \"https://api.mimo.example.com\"","handlingStrategy":"try-catch","validationCode":"if err := ctx.Err(); err != nil { return err }\nif u, err := url.Parse(cfg.BaseURL); err != nil || u.Scheme == \"\" || strings.ContainsAny(cfg.BaseURL, \" \\t\") { return fmt.Errorf(\"invalid mimo base_url %q\", cfg.BaseURL) }","typeGuard":"func validContext(ctx context.Context) bool { return ctx != nil && ctx.Err() == nil }","tryCatchPattern":"audio, format, err := tts.Synthesize(ctx, text, voice)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {\n        // use a fresh, longer-lived context and retry once\n    }\n    return err\n}","preventionTips":["Validate mimo base_url with url.Parse at config load","Give TTS calls their own timeout budget separate from the parent request","Strip whitespace from TOML string config values"],"tags":["go","http","tts","mimo","context-canceled"],"backgroundTag":"invalid-url","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"}