{"record":{"id":"7cfcfaf7209c804a","repo":"apache/beam","slug":"failed-to-initialize-google-cloud-healthcare-service-reason","errorCode":null,"errorMessage":"Failed to initialize Google Cloud Healthcare Service. Reason: ","messagePattern":"Failed to initialize Google Cloud Healthcare Service\\. Reason: ","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"sdks/go/pkg/beam/io/fhirio/common.go","lineNumber":99,"sourceCode":"\tFailures  int64 `json:\"failure,string\"`\n}\n\ntype fhirStoreClient interface {\n\treadResource(resourcePath []byte) (*http.Response, error)\n\texecuteBundle(storePath string, bundle string) (*http.Response, error)\n\tsearch(storePath, resourceType string, queries map[string]string, pageToken string) (*http.Response, error)\n\tdeidentify(srcStorePath, dstStorePath string, deidConfig *healthcare.DeidentifyConfig) (operationResults, error)\n\timportResources(storePath, gcsURI string, contentStructure ContentStructure) (operationResults, error)\n}\n\ntype fhirStoreClientImpl struct {\n\thealthcareService *healthcare.Service\n}\n\nfunc newFhirStoreClient() *fhirStoreClientImpl {\n\thealthcareService, err := healthcare.NewService(context.Background(), option.WithUserAgent(UserAgent))\n\tif err != nil {\n\t\tpanic(\"Failed to initialize Google Cloud Healthcare Service. Reason: \" + err.Error())\n\t}\n\treturn &fhirStoreClientImpl{healthcareService}\n}\n\nfunc (c *fhirStoreClientImpl) fhirService() *healthcare.ProjectsLocationsDatasetsFhirStoresFhirService {\n\treturn c.healthcareService.Projects.Locations.Datasets.FhirStores.Fhir\n}\n\nfunc (c *fhirStoreClientImpl) fhirStoreService() *healthcare.ProjectsLocationsDatasetsFhirStoresService {\n\treturn c.healthcareService.Projects.Locations.Datasets.FhirStores\n}\n\nfunc (c *fhirStoreClientImpl) readResource(resourcePath []byte) (*http.Response, error) {\n\treturn c.fhirService().Read(string(resourcePath)).Do()\n}\n\nfunc (c *fhirStoreClientImpl) executeBundle(storePath, bundle string) (*http.Response, error) {\n\treturn c.fhirService().ExecuteBundle(storePath, strings.NewReader(bundle)).Do()","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/fhirio/common.go#L81-L117","documentation":"newFhirStoreClient in fhirio panics when healthcare.NewService fails to construct the Google Cloud Healthcare API client. This typically means Google Cloud credentials are missing/invalid or the default options (user agent) could not be applied, so no FHIR store operations can proceed.","triggerScenarios":"Running a fhirio pipeline (search/read/delete via setup -> newFhirStoreClient) with no Application Default Credentials available: GOOGLE_APPLICATION_CREDENTIALS unset, no metadata server, or a malformed credentials file.","commonSituations":"Running locally without 'gcloud auth application-default login'; deploying to an environment without the proper service-account scopes; a corrupted or wrong-project credentials JSON; network/DNS failure reaching the Google auth endpoints.","solutions":["Set GOOGLE_APPLICATION_CREDENTIALS to a valid service-account JSON key, or run 'gcloud auth application-default login' locally.","Ensure the runtime environment (GCE/GKE/Cloud Run) has the Cloud Healthcare scopes and a service account with healthcare permissions.","Validate credentials before starting the pipeline (e.g. create the healthcare client yourself in a pre-check).","Check network access to oauth2.googleapis.com and healthcare.googleapis.com."],"exampleFix":"// before\nbeam.Init() // no credentials configured\n\n// after\nos.Setenv(\"GOOGLE_APPLICATION_CREDENTIALS\", \"/path/to/sa-key.json\")\nbeam.Init()","handlingStrategy":"validation","validationCode":"if _, err := healthcare.NewService(context.Background()); err != nil {\n    return fmt.Errorf(\"Google Cloud Healthcare client unavailable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Fatalf(\"Healthcare service init failed: %v\", r)\n    }\n}()","preventionTips":["Ensure GOOGLE_APPLICATION_CREDENTIALS or workload identity is configured before beam.Init().","Run 'gcloud auth application-default login' in dev environments.","Grant the runtime service account Cloud Healthcare roles and correct OAuth scopes.","Smoke-test client construction outside the pipeline first."],"tags":["go","fhir","gcp","authentication","panic"],"backgroundTag":"missing-credentials","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}