{"record":{"id":"fcb0312fd9d15b99","repo":"vxcontrol/pentagi","slug":"failed-to-create-google-search-service-w","errorCode":null,"errorMessage":"failed to create google search service: %w","messagePattern":"failed to create google search service: %w","errorType":"exception","errorClass":"FatalError","httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/searchers/google.go","lineNumber":57,"sourceCode":"\t}\n\n\tctx, observation := obs.Observer.NewObservation(ctx)\n\n\tnumResults := int64(req.MaxResults)\n\tif numResults < 1 || numResults > googleMaxResults {\n\t\tnumResults = googleMaxResults\n\t}\n\n\tlogger := logrus.WithContext(ctx).WithFields(logrus.Fields{\n\t\t\"engine\":      \"google\",\n\t\t\"query\":       req.Query[:min(len(req.Query), 1000)],\n\t\t\"num_results\": numResults,\n\t})\n\n\tsvc, err := g.newSearchService(ctx)\n\tif err != nil {\n\t\tlogger.WithError(err).Error(\"failed to create google search service\")\n\t\treturn \"\", Fatal(fmt.Errorf(\"failed to create google search service: %w\", err))\n\t}\n\n\tresult, err := g.search(ctx, svc, req.Query, numResults)\n\tif err != nil {\n\t\tobservation.Event(\n\t\t\tlangfuse.WithEventName(\"search engine error\"),\n\t\t\tlangfuse.WithEventInput(req.Query),\n\t\t\tlangfuse.WithEventStatus(err.Error()),\n\t\t\tlangfuse.WithEventLevel(langfuse.ObservationLevelWarning),\n\t\t\tlangfuse.WithEventMetadata(langfuse.Metadata{\n\t\t\t\t\"engine\":      \"google\",\n\t\t\t\t\"query\":       req.Query,\n\t\t\t\t\"max_results\": numResults,\n\t\t\t\t\"error\":       err.Error(),\n\t\t\t}),\n\t\t)\n\n\t\tobs.LogErrorOrCancel(logger, err, \"failed to search in google\")","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/searchers/google.go#L39-L75","documentation":"google.Handle fails to build the Custom Search JSON API client and wraps the cause in Fatal(fmt.Errorf(\"failed to create google search service: %w\", err)). This is Fatal (not Retryable), so the web_search orchestrator will not retry Google for this query and will move on. The underlying cause is almost always the nested 'failed to create http client' or customsearch.NewService failure.","triggerScenarios":"g.newSearchService(ctx) errors: system.GetHTTPClient fails (proxy/TLS config invalid) or customsearch.NewService(ctx, option.WithHTTPClient(client)) fails to initialize the google.golang.org/api service.","commonSituations":"Invalid HTTPS_PROXY/HTTP_PROXY env vars or bad proxy CA certs on Google API search calls; corrupt google.golang.org/api module options; context already canceled when Handle is invoked.","solutions":["Read the wrapped cause: if it is 'failed to create http client', fix proxy/TLS settings (HTTPS_PROXY, CA bundle) used by system.GetHTTPClient","Ensure GOOGLE_API_KEY and GOOGLE_CX_KEY are set — although IsAvailable() guards this, verify the config actually loaded","If the context is canceled, check upstream cancellation/timeouts rather than Google config","Retry the flow; since the error is Fatal the orchestrator skips Google, so fix the root cause to restore Google results"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// guard config before calling the engine\nif cfg.GoogleAPIKey == \"\" || cfg.GoogleCXKey == \"\" {\n    // engine unavailable (IsAvailable() would return false)\n}","typeGuard":null,"tryCatchPattern":"result, err := googleSearcher.Handle(ctx, req)\nif err != nil {\n    if searchers.IsFatal(err) && strings.Contains(err.Error(), \"failed to create google search service\") {\n        log.Errorf(\"google client init failed: %v\", err) // fix proxy/TLS, don't retry\n        return fallbackSearcher.Handle(ctx, req)\n    }\n    return \"\", err\n}","preventionTips":["Validate GOOGLE_API_KEY/GOOGLE_CX_KEY and proxy env vars at startup","Smoke-test system.GetHTTPClient during app init and fail fast on bad config","Avoid canceling contexts passed into Handle before the service is built"],"tags":["google","customsearch","client-init","fatal"],"backgroundTag":"api-client-init-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}