{"record":{"id":"5c904b88f26a80ad","repo":"chenhg5/cc-connect","slug":"write-audio-w","errorCode":null,"errorMessage":"write audio: %w","messagePattern":"write audio: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/speech.go","lineNumber":67,"sourceCode":"\t\tAPIKey:  apiKey,\n\t\tBaseURL: strings.TrimRight(baseURL, \"/\"),\n\t\tModel:   model,\n\t\tClient:  &http.Client{Timeout: 5 * time.Minute},\n\t}\n}\n\nfunc (w *OpenAIWhisper) Transcribe(ctx context.Context, audio []byte, format string, lang string) (string, error) {\n\text := formatToExt(format)\n\n\tvar buf bytes.Buffer\n\twriter := multipart.NewWriter(&buf)\n\n\tpart, err := writer.CreateFormFile(\"file\", \"audio.\"+ext)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"create form file: %w\", err)\n\t}\n\tif _, err := part.Write(audio); err != nil {\n\t\treturn \"\", fmt.Errorf(\"write audio: %w\", err)\n\t}\n\t_ = writer.WriteField(\"model\", w.Model)\n\t_ = writer.WriteField(\"response_format\", \"text\")\n\tif lang != \"\" {\n\t\t_ = writer.WriteField(\"language\", lang)\n\t}\n\twriter.Close()\n\n\turl := w.BaseURL + \"/audio/transcriptions\"\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, url, &buf)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"create request: %w\", err)\n\t}\n\treq.Header.Set(\"Authorization\", \"Bearer \"+w.APIKey)\n\treq.Header.Set(\"Content-Type\", writer.FormDataContentType())\n\n\tresp, err := w.Client.Do(req)\n\tif err != nil {","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/speech.go#L49-L85","documentation":"After the multipart part for the audio file is created, the raw audio bytes are written into it via part.Write. If that write fails, the bytes.Buffer backing the writer returned an error (typically allocation/OOM for very large audio payloads). Transcribe wraps it as 'write audio: %w' and aborts the transcription.","triggerScenarios":"Transcribe called with an audio []byte large enough that the in-memory bytes.Buffer fails to grow, or any underlying write error from the multipart part writer.","commonSituations":"Transcribing long voice messages (multi-MB audio) on memory-constrained hosts or containers with low memory limits; OOM-adjacent failures.","solutions":["Increase available memory / container memory limits for large audio files","Truncate or chunk very long audio before transcription","Check the wrapped error for out-of-memory indications"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if len(audio) == 0 {\n    return \"\", fmt.Errorf(\"empty audio payload\")\n}\nif maxAudioBytes > 0 && len(audio) > maxAudioBytes {\n    return \"\", fmt.Errorf(\"audio too large: %d bytes\", len(audio))\n}","typeGuard":null,"tryCatchPattern":"if err := transcribe(ctx, audio); err != nil {\n    var wrapped interface{ Unwrap() error }\n    if errors.As(err, new(*errors.Error)) || strings.Contains(err.Error(), \"write audio\") {\n        slog.Warn(\"audio write failed, likely memory pressure\", \"size\", len(audio))\n    }\n}","preventionTips":["Cap audio duration/size before transcription on memory-constrained hosts","Set container memory limits generously relative to max expected audio size","Monitor Go heap usage when processing many concurrent voice messages"],"tags":["multipart","stt","memory"],"backgroundTag":"file-write-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"}