{"record":{"id":"89f9310a8b13ffb8","repo":"googleapis/mcp-toolbox","slug":"failed-to-create-request-w-89f931","errorCode":null,"errorMessage":"failed to create request: %w","messagePattern":"failed to create request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/looker/lookerconversationalanalytics/lookerconversationalanalytics.go","lineNumber":433,"sourceCode":"type AnalysisMessage struct {\n\tQuery         AnalysisQuery `json:\"query,omitempty\"`\n\tProgressEvent AnalysisEvent `json:\"progressEvent,omitempty\"`\n}\n\n// ErrorResponse represents an error message from the API.\ntype ErrorMessage struct {\n\tText string `json:\"text\"`\n}\n\nfunc getStream(ctx context.Context, client *http.Client, url string, payload CAPayload, headers map[string]string) ([]map[string]any, error) {\n\tpayloadBytes, err := json.Marshal(payload)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal payload: %w\", err)\n\t}\n\n\treq, err := http.NewRequest(\"POST\", url, bytes.NewBuffer(payloadBytes))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create request: %w\", err)\n\t}\n\tfor k, v := range headers {\n\t\treq.Header.Set(k, v)\n\t}\n\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to send request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tbody, _ := io.ReadAll(resp.Body)\n\t\treturn nil, fmt.Errorf(\"API returned non-200 status: %d %s\", resp.StatusCode, string(body))\n\t}\n\n\tvar messages []map[string]any\n\tdecoder := json.NewDecoder(resp.Body)","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/looker/lookerconversationalanalytics/lookerconversationalanalytics.go#L415-L451","documentation":"getStream builds the http POST request to the Conversational Analytics streaming endpoint with http.NewRequest. If request construction fails (typically a malformed URL string, e.g. unparsable characters or an invalid base URL), this wrapped error is returned before any network activity.","triggerScenarios":"Calling getStream with a url string that fails url.Parse — e.g. a misconfigured Conversational Analytics API base URL containing spaces or control characters, or an empty/invalid endpoint assembled from config.","commonSituations":"Wrong or malformed GOOGLE_CLOUD_API_ENDPOINT-style base URL in configuration; template interpolation injecting whitespace or invalid characters; proxy/region overrides producing bad URLs.","solutions":["Verify the API endpoint URL is a valid absolute https URL and log it before the call","Trim whitespace/control characters from the configured base URL","Fix the configuration providing the URL (env var or config field)","Check the wrapped %w error for the exact parse failure from net/url"],"exampleFix":"// before\nendpoint := \" https://cloudaicompanion.googleapis.com \"\n// after\nendpoint := strings.TrimSpace(\"https://cloudaicompanion.googleapis.com\")","handlingStrategy":"validation","validationCode":"if u, err := url.Parse(endpoint); err != nil || u.Scheme == \"\" || u.Host == \"\" {\n\treturn fmt.Errorf(\"invalid endpoint URL: %q\", endpoint)\n}","typeGuard":null,"tryCatchPattern":"_, err := http.NewRequest(\"POST\", endpoint, body)\nif err != nil {\n\treturn fmt.Errorf(\"check endpoint config: %w\", err)\n}","preventionTips":["Validate configured base URLs with url.Parse at startup","Trim and sanitize env-derived endpoint strings","Pin endpoints to known-good https URLs in config"],"tags":["looker","http","url","network"],"backgroundTag":"invalid-url","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}