{"record":{"id":"554fbac2ba1c5a5f","repo":"sipeed/picoclaw","slug":"failed-to-create-request-w-554fba","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/whisper_transcriber.go","lineNumber":188,"sourceCode":"\n\tif err = writer.Close(); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to close multipart writer: %w\", err)\n\t}\n\n\treturn t.doRequest(ctx, &requestBody, writer.FormDataContentType(), fileInfo.Size())\n}\n\nfunc (t *WhisperTranscriber) doRequest(\n\tctx context.Context,\n\trequestBody *bytes.Buffer,\n\tcontentType string,\n\tfileSize int64,\n) (*TranscriptionResponse, error) {\n\turl := t.transcriptionURL()\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", url, requestBody)\n\tif err != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to create whisper 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\", contentType)\n\tif t.apiKey != \"\" {\n\t\treq.Header.Set(\"Authorization\", \"Bearer \"+t.apiKey)\n\t}\n\n\tlogger.DebugCF(\"voice\", \"Sending whisper transcription request\", map[string]any{\n\t\t\"file_size_bytes\":    fileSize,\n\t\t\"model\":              t.modelID,\n\t\t\"provider\":           t.providerName,\n\t\t\"request_size_bytes\": requestBody.Len(),\n\t\t\"url\":                url,\n\t})\n\n\tresp, err := t.httpClient.Do(req)\n\tif err != nil {\n\t\tlogger.ErrorCF(\"voice\", \"Failed to send whisper request\", map[string]any{\"error\": err})","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/audio/asr/whisper_transcriber.go#L170-L206","documentation":"Returned by WhisperTranscriber.doRequest when http.NewRequestWithContext rejects the POST URL built by transcriptionURL() (apiBase + '/audio/transcriptions'). NewRequestWithContext fails on a malformed URL: missing scheme, whitespace or control characters, or invalid percent-encoding in the configured api_base. The method (POST) and body are always valid.","triggerScenarios":"api_base configured as 'api.groq.com/openai/v1' without https://; trailing whitespace or newline in the config value; a custom endpoint path with characters that break url.Parse.","commonSituations":"Hand-edited config files; environment variables for the API base missing the scheme; copy-paste artifacts such as trailing spaces.","solutions":["Set api_base to a full URL including scheme, e.g. https://api.groq.com/openai/v1","Trim whitespace from the api_base config value","url.Parse the base at startup and fail configuration early","Log transcriptionURL() output to see the exact string being rejected"],"exampleFix":"// before\napiBase := `api.groq.com/openai/v1` // missing scheme -> request creation fails\n// after\napiBase := `https://api.groq.com/openai/v1`\nif _, err := url.Parse(apiBase); err != nil {\n    return fmt.Errorf(`invalid api_base: %w`, err)\n}","handlingStrategy":"validation","validationCode":"u, err := url.Parse(strings.TrimSpace(cfg.APIBase))\nif err != nil || u.Scheme == `` || u.Host == `` {\n    return fmt.Errorf(`invalid api_base %q: include scheme and host`, cfg.APIBase)\n}","typeGuard":"func isInvalidURL(err error) bool {\n    return err != nil && (strings.Contains(err.Error(), `invalid URI`) ||\n        strings.Contains(err.Error(), `missing protocol scheme`) ||\n        strings.Contains(err.Error(), `invalid control character`))\n}","tryCatchPattern":"if err != nil {\n    // non-retriable config error: fix api_base (add https://, strip whitespace) before retrying\n}","preventionTips":["Validate api_base with url.Parse once at startup","Always include the scheme in configured base URLs","Trim whitespace from config-supplied URLs before use"],"tags":["config","url","whisper","asr","http"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}