{"record":{"id":"74d636bd951e6e25","repo":"GoogleContainerTools/skaffold","slug":"unable-to-guess-gcp-projectid-from-image-name-s","errorCode":null,"errorMessage":"unable to guess GCP projectID from image name [%s]","messagePattern":"unable to guess GCP projectID from image name \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/gcp/projectid.go","lineNumber":42,"sourceCode":")\n\n// ExtractProjectID extracts the GCP projectID from a docker image name\n// This only works if the imageName is pushed to gcr.io.\nfunc ExtractProjectID(imageName string) (string, error) {\n\tref, err := name.ParseReference(imageName, name.WeakValidation)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"parsing image name %q: %w\", imageName, err)\n\t}\n\n\tregistry := ref.Context().Registry.Name()\n\tif registry == \"gcr.io\" || strings.HasSuffix(registry, \".gcr.io\") || strings.HasSuffix(registry, \"-docker.pkg.dev\") {\n\t\tparts := strings.Split(imageName, \"/\")\n\t\tif len(parts) >= 2 {\n\t\t\treturn parts[1], nil\n\t\t}\n\t}\n\n\treturn \"\", fmt.Errorf(\"unable to guess GCP projectID from image name [%s]\", imageName)\n}\n","sourceCodeStart":24,"sourceCodeEnd":44,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/gcp/projectid.go#L24-L44","documentation":"ExtractProjectID only supports guessing the project ID when the image's registry is gcr.io, a subdomain of gcr.io, or a *-docker.pkg.dev Artifact Registry host, and the name has at least two path components. If neither the parse nor the registry check yields a project, it returns this descriptive error.","triggerScenarios":"Calling ExtractProjectID with an image pushed to a non-Google registry (docker.io, quay.io, ghcr.io) or a GCR-style name with fewer than 2 path components (e.g. just 'myimage').","commonSituations":"Passing a Docker Hub image and expecting a GCP project; local images named without a registry/project prefix; Artifact Registry hosts with unexpected suffixes or custom domains.","solutions":["Use a fully qualified gcr.io or *-docker.pkg.dev image name containing the project as the first path segment (e.g. gcr.io/my-project/app).","Prepend the project path to local names: 'myimage' -> 'gcr.io/my-project/myimage'.","If the image is not on a Google registry, obtain the project ID from configuration instead of calling ExtractProjectID.","Verify the registry suffix is exactly gcr.io, *.gcr.io, or *-docker.pkg.dev."],"exampleFix":"// before\nid, err := gcp.ExtractProjectID(\"myimage\")            // fails\nid2, _ := gcp.ExtractProjectID(\"quay.io/org/img\")     // fails\n// after\nid, err := gcp.ExtractProjectID(\"gcr.io/my-project/myimage\")","handlingStrategy":"validation","validationCode":"func canInferProject(imageName string) bool {\n    ref, err := name.ParseReference(imageName, name.WeakValidation)\n    if err != nil {\n        return false\n    }\n    reg := ref.Context().Registry.Name()\n    gcrish := reg == \"gcr.io\" || strings.HasSuffix(reg, \".gcr.io\") || strings.HasSuffix(reg, \"-docker.pkg.dev\")\n    return gcrish && len(strings.Split(imageName, \"/\")) >= 2\n}\n// call ExtractProjectID only if canInferProject(imageName)","typeGuard":null,"tryCatchPattern":"projectID, err := gcp.ExtractProjectID(imageName)\nif err != nil {\n    return fmt.Errorf(\"cannot infer GCP project from %q; supply projectID from config instead\", imageName)\n}","preventionTips":["Only use ExtractProjectID for images on gcr.io, *.gcr.io, or *-docker.pkg.dev.","Ensure the image name includes the project as the first path segment.","For non-Google registries, carry the project ID in skaffold.yaml/config rather than inferring it."],"tags":["gcp","image-name","project-id","gcr"],"backgroundTag":"cannot-infer-gcp-project","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}