{"record":{"id":"071d97154a3ca74b","repo":"googleapis/mcp-toolbox","slug":"failed-to-create-http-request-w-071d97","errorCode":null,"errorMessage":"failed to create HTTP request: %w","messagePattern":"failed to create HTTP request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/firestore/firestore.go","lineNumber":917,"sourceCode":"\t\t\t\t\t\t\t\"args\": []map[string]any{\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\"stringValue\": mqlQuery,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t\tbodyBytes, err = json.Marshal(payload)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to marshal pipeline payload: %w\", err)\n\t\t}\n\t}\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(bodyBytes))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create HTTP request: %w\", err)\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"User-Agent\", userAgent)\n\treq.Header.Set(\"x-goog-request-params\", fmt.Sprintf(\"project_id=%s&database_id=%s\", s.GetProjectId(), s.GetDatabaseId()))\n\treq.Header.Set(\"x-goog-firestore-api-requester\", \"querydata\")\n\n\tresp, err := httpClient.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to execute pipeline request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\trespBody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read response body: %w\", err)\n\t}\n\n\tif resp.StatusCode < 200 || resp.StatusCode >= 300 {","sourceCodeStart":899,"sourceCodeEnd":935,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/firestore/firestore.go#L899-L935","documentation":"This error wraps a failure from http.NewRequestWithContext inside ExecuteMQL, which sends an MQL (MongoDB Query Language) pipeline to the Firestore executePipeline REST endpoint. It means the HTTP request object could not be constructed before any network traffic occurred — typically a malformed URL or an invalid body reader. Since the request never left the process, no server-side status or response exists.","triggerScenarios":"http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(bodyBytes)) returns non-nil err — practically only when the composed executePipeline URL (built from project/database IDs) fails to parse, or the context passed to ExecuteMQL is already cancelled/deadlined.","commonSituations":"A misconfigured project or database id producing an invalid URL (e.g. empty project id, illegal characters); passing a ctx that was cancelled before the call; URL-encoding bugs in the endpoint assembly.","solutions":["Print/inspect the composed url just before http.NewRequestWithContext and verify the project and database IDs are valid (non-empty, URL-safe)","Check the context passed to ExecuteMQL is live (not already cancelled/expired) at call time","Log the wrapped err (%w) to see the underlying url.Parse error and fix the offending component"],"exampleFix":"// before\nclient.ExecuteMQL(ctx, pipeline) // ctx already cancelled upstream\n// after\nif err := ctx.Err(); err != nil { return err }\nresult, err := client.ExecuteMQL(ctx, pipeline)","handlingStrategy":"validation","validationCode":"if ctx.Err() != nil { return fmt.Errorf(\"context already done: %w\", ctx.Err()) }\nif project == \"\" || database == \"\" { return fmt.Errorf(\"project and database must be set\") }\n// url is built internally; ensure IDs are URL-safe:","typeGuard":null,"tryCatchPattern":"res, err := src.ExecuteMQL(ctx, pipeline)\nif err != nil && strings.Contains(err.Error(), \"failed to create HTTP request\") {\n    log.Printf(\"request construction failed (check URL/ctx): %v\", err)\n}","preventionTips":["Always pass a live, non-cancelled context to ExecuteMQL","Keep project/database IDs URL-safe and non-empty","Unwrap and log the %w cause to see the exact url.Parse failure"],"tags":["firestore","http","request-construction","network"],"backgroundTag":"http-request-build-failed","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"}