{"record":{"id":"4bda653655d12565","repo":"juicedata/juicefs","slug":"google-cloud-project-environment-variable-must-be","errorCode":null,"errorMessage":"GOOGLE_CLOUD_PROJECT environment variable must be set","messagePattern":"GOOGLE_CLOUD_PROJECT environment variable must be set","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/object/gs.go","lineNumber":79,"sourceCode":"}\n\nfunc (g *gs) Create(ctx context.Context) error {\n\t// check if the bucket is already exists\n\tif objs, _, _, err := g.List(ctx, \"\", \"\", \"\", \"\", 1, true); err == nil && len(objs) > 0 {\n\t\treturn nil\n\t}\n\tprojectID := os.Getenv(\"GOOGLE_CLOUD_PROJECT\")\n\tif projectID == \"\" {\n\t\tprojectID, _ = metadata.ProjectIDWithContext(ctx)\n\t}\n\tif projectID == \"\" {\n\t\tcred, err := google.FindDefaultCredentials(ctx)\n\t\tif err == nil {\n\t\t\tprojectID = cred.ProjectID\n\t\t}\n\t}\n\tif projectID == \"\" {\n\t\treturn errors.New(\"GOOGLE_CLOUD_PROJECT environment variable must be set\")\n\t}\n\t// Guess region when region is not provided\n\tif g.region == \"\" {\n\t\tzone, err := metadata.ZoneWithContext(ctx)\n\t\tif err == nil && len(zone) > 2 {\n\t\t\tg.region = zone[:len(zone)-2]\n\t\t}\n\t}\n\n\terr := g.getClient().Bucket(g.bucket).Create(ctx, projectID, &storage.BucketAttrs{\n\t\tName:         g.bucket,\n\t\tStorageClass: g.tiers[0].Sc,\n\t\tLocation:     g.region,\n\t})\n\tif err != nil && strings.Contains(err.Error(), \"You already own this bucket\") {\n\t\treturn nil\n\t}\n\treturn err","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/object/gs.go#L61-L97","documentation":"Creating a new GCS bucket (gsStore.Create) needs a project ID; when it was not supplied in the URL/config and default credentials carry no project, the code requires the GOOGLE_CLOUD_PROJECT environment variable and errors otherwise.","triggerScenarios":"Running juicefs format (bucket creation) against gs:// without ?project= in the bucket URL, when the service account/ADC credentials have no project_id field (e.g. a raw JSON key without it, or metadata server unavailable).","commonSituations":"CI machines with GOOGLE_APPLICATION_CREDENTIALS set to a key file lacking project_id; on-prem/VMs outside GCP where the metadata zone lookup fails; typos like GOOGLE_CLOUND_PROJECT.","solutions":["Export GOOGLE_CLOUD_PROJECT=<your-gcp-project-id> before running the command.","Append the project to the bucket URL, e.g. gs://mybucket?project=my-project (or pass region/project in the format options).","Use credentials whose JSON includes project_id (re-download the service account key), so FindDefaultCredentials resolves it.","Fix the env var name spelling and ensure it is exported in the sudo/CI environment."],"exampleFix":"// before\njuicefs format \"gs://mybucket\" myjfs\n// after\nexport GOOGLE_CLOUD_PROJECT=my-gcp-project\njuicefs format \"gs://mybucket\" myjfs","handlingStrategy":"validation","validationCode":"if os.Getenv(\"GOOGLE_CLOUD_PROJECT\") == \"\" && !strings.Contains(bucketURL, \"project=\") {\n    return fmt.Errorf(\"set GOOGLE_CLOUD_PROJECT or add ?project=<id> to the gs:// URL\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := object.CreateStorage(ctx, \"gs\", \"bucket\", \"\", \"\"); err != nil {\n    if strings.Contains(err.Error(), \"GOOGLE_CLOUD_PROJECT\") {\n        return fmt.Errorf(\"GCS project missing: export GOOGLE_CLOUD_PROJECT or use gs://bucket?project=ID\")\n    }\n    return err\n}","preventionTips":["Always export GOOGLE_CLOUD_PROJECT in environments touching GCS buckets for creation.","Embed ?project=ID in the gs:// URL for explicit, env-independent configs.","Use service-account JSON keys that include project_id."],"tags":["gcs","object-storage","env-var","gcp"],"backgroundTag":"missing-env-var","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}