chenhg5/cc-connect · error
marshal request: %w
Error message
marshal request: %w
What it means
QwenASR.Transcribe builds a chat/completions request containing the audio as a base64 data URI and marshals it with encoding/json. json.Marshal can only fail here if a value in reqBody is unsupported (e.g. a channel, func, or cyclic value). With the current map[string]any structure of plain strings this is effectively unreachable; the wrap is defensive.
Source
Thrown at core/speech.go:160
"model": q.Model,
"messages": []map[string]any{
{
"role": "user",
"content": []map[string]any{
{
"type": "input_audio",
"input_audio": map[string]any{
"data": dataURI,
},
},
},
},
},
}
jsonData, err := json.Marshal(reqBody)
if err != nil {
return "", fmt.Errorf("marshal request: %w", err)
}
url := q.BaseURL + "/chat/completions"
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(jsonData))
if err != nil {
return "", fmt.Errorf("create request: %w", err)
}
req.Header.Set("Authorization", "Bearer "+q.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := q.Client.Do(req)
if err != nil {
return "", fmt.Errorf("qwen asr request: %w", err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {View on GitHub (pinned to 4000b2338a)
Solutions
- Inspect the wrapped json error for the unsupported type name
- Replace unsupported field types in reqBody with JSON-serializable types (string, []any, map[string]any)
- Remove cyclic references if custom structs were introduced
Defensive patterns
Strategy: try-catch
Try / catch
text, err := stt.Transcribe(ctx, audio, format, lang)
if err != nil && strings.Contains(err.Error(), "marshal request") {
slog.Error("qwen request body not JSON-serializable", "err", err)
} Prevention
- Keep reqBody limited to JSON-native types (string, map[string]any, []any)
- Never insert func/chan values into request maps
- If adding fields, test json.Marshal on the body in a unit test
When it happens
Trigger: json.Marshal returns an error for the request body — only possible if reqBody is modified to contain unsupported Go types (func, chan, or a value with a MarshalJSON method that returns an error).
Common situations: Essentially never hit by users; could appear if someone customizes the request-building code and inserts an unsupported type.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- parse response: %w
- qwen tts: marshal request: %w
- qwen tts: parse response: %w
- parse existing Agy hooks %s: %w
- marshal Agy permission hook: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/566664f685291ab3.
Report an issue: GitHub.