{"record":{"id":"de8683724b346edc","repo":"sipeed/picoclaw","slug":"failed-to-create-request-w","errorCode":null,"errorMessage":"failed to create request: %w","messagePattern":"failed to create request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/audio/asr/elevenlabs_transcriber.go","lineNumber":95,"sourceCode":"\tif _, err = io.Copy(part, audioFile); err != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to copy file content\", map[string]any{\"error\": err})\n\t\treturn nil, fmt.Errorf(\"failed to copy file content: %w\", err)\n\t}\n\n\tif err = writer.WriteField(\"model_id\", t.modelID); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to write model_id field: %w\", err)\n\t}\n\n\tif err = writer.Close(); err != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to close multipart writer\", map[string]any{\"error\": err})\n\t\treturn nil, fmt.Errorf(\"failed to close multipart writer: %w\", err)\n\t}\n\n\turl := t.apiBase + \"/v1/speech-to-text\"\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", url, &requestBody)\n\tif err != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to create request\", map[string]any{\"error\": err})\n\t\treturn nil, fmt.Errorf(\"failed to create request: %w\", err)\n\t}\n\n\treq.Header.Set(\"Content-Type\", writer.FormDataContentType())\n\treq.Header.Set(\"Xi-Api-Key\", t.apiKey)\n\n\tlogger.DebugCF(\"voice\", \"Sending transcription request to ElevenLabs API\", map[string]any{\n\t\t\"url\":                url,\n\t\t\"request_size_bytes\": requestBody.Len(),\n\t\t\"file_size_bytes\":    fileInfo.Size(),\n\t})\n\n\tresp, err := t.httpClient.Do(req)\n\tif err != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to send request\", map[string]any{\"error\": err})\n\t\treturn nil, fmt.Errorf(\"failed to send request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/audio/asr/elevenlabs_transcriber.go#L77-L113","documentation":"Thrown when http.NewRequestWithContext cannot construct the POST request to t.apiBase + \"/v1/speech-to-text\" in ElevenLabsTranscriber.Transcribe. The method and body are always valid, so the failure is a malformed URL: url.Parse rejects control characters, spaces, or a missing/invalid scheme/host. The error wraps *url.Error with Op 'parse'.","triggerScenarios":"apiBase passed to NewElevenLabsTranscriber contains whitespace, a trailing newline (env var read with newline), missing scheme (api.elevenlabs.io instead of https://...), or an unreachable-to-parse string. Note the constructor defaults to https://api.elevenlabs.io only when apiBase is empty.","commonSituations":"ELEVENLABS_API_BASE-style config value with trailing \\r (Windows-edited config) or missing scheme; proxy endpoint URL typo; environment variable interpolation inserting quotes.","solutions":["Print the apiBase value with %q to expose hidden whitespace/newlines, then fix the config source.","Validate the base URL once at construction: url.Parse and require a host and http(s) scheme.","Omit apiBase to use the default https://api.elevenlabs.io if unsure."],"exampleFix":"// before\ntr := asr.NewElevenLabsTranscriber(key, os.Getenv(\"EL_BASE\"), \"\")\n\n// after\nbase := strings.TrimSpace(os.Getenv(\"EL_BASE\"))\nif base != \"\" {\n    u, err := url.Parse(base)\n    if err != nil || u.Host == \"\" || (u.Scheme != \"http\" && u.Scheme != \"https\") {\n        return nil, fmt.Errorf(\"invalid ElevenLabs api base %q\", base)\n    }\n}\ntr := asr.NewElevenLabsTranscriber(key, base, \"\")","handlingStrategy":"validation","validationCode":"func validAPIBase(base string) error {\n    if base == \"\" { return nil } // constructor defaults to https://api.elevenlabs.io\n    u, err := url.Parse(strings.TrimSpace(base))\n    if err != nil { return fmt.Errorf(\"unparseable api base: %w\", err) }\n    if u.Host == \"\" || (u.Scheme != \"http\" && u.Scheme != \"https\") {\n        return fmt.Errorf(\"api base missing scheme/host: %q\", base)\n    }\n    return nil\n}","typeGuard":"func isURLParseErr(err error) bool {\n    var ue *url.Error\n    return errors.As(err, &ue) && ue.Op == \"parse\"\n}","tryCatchPattern":"if _, err := el.Transcribe(ctx, path); err != nil {\n    if isURLParseErr(err) {\n        return fmt.Errorf(\"ElevenLabs apiBase misconfigured (%q): fix the env/config value\", baseCfg)\n    }\n    return err\n}","preventionTips":["Trim whitespace from URL env vars at load time.","Validate URLs once at construction, not per request.","Log config values with %q, never %s, to catch hidden characters."],"tags":["url","configuration","elevenlabs","http","go"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}