{"record":{"id":"193d7e06c2f275f8","repo":"GoogleContainerTools/skaffold","slug":"parsing-image-name-q-w","errorCode":null,"errorMessage":"parsing image name %q: %w","messagePattern":"parsing image name %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/gcp/projectid.go","lineNumber":31,"sourceCode":"See the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\npackage gcp\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\n\t\"github.com/google/go-containerregistry/pkg/name\"\n)\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":13,"sourceCodeEnd":44,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/gcp/projectid.go#L13-L44","documentation":"ExtractProjectID infers the GCP project ID from a container image name by parsing it as a registry reference and requiring the registry to be gcr.io, *.gcr.io, or *-docker.pkg.dev. If the image name cannot be parsed as a valid reference at all, it wraps the parse error with 'parsing image name'.","triggerScenarios":"Calling ExtractProjectID with a malformed image string: missing tag/registry components, illegal characters, an empty string, or a full URL with scheme (https://) instead of an image reference.","commonSituations":"Passing a raw Docker image digest URL or an image built with an invalid tag; typos like double colons (name:tag:extra); accidentally passing 'docker.io/library/x' expecting a GCP project; using a local-only name like 'myapp' that go-containerregistry rejects as a reference.","solutions":["Fix the image name to be a valid registry reference (e.g. gcr.io/project/name:tag).","Remove any URL scheme ('https://') or stray port/characters from the string.","Remember ExtractProjectID only works for gcr.io/*.gcr.io/*-docker.pkg.dev images — pass such an image or supply the project ID directly.","Read the wrapped cause from go-containerregistry's name.ParseReference for the exact syntax problem."],"exampleFix":"// before\nprojectID, _ := gcp.ExtractProjectID(\"https://gcr.io/my-proj/img\")\n// after\nprojectID, _ := gcp.ExtractProjectID(\"gcr.io/my-proj/img:latest\")","handlingStrategy":"validation","validationCode":"func isValidImageRef(imageName string) bool {\n    _, err := name.ParseReference(imageName, name.WeakValidation)\n    return err == nil\n}\n// call ExtractProjectID only if isValidImageRef(imageName)","typeGuard":"func isParseErr(err error) bool {\n    return strings.Contains(err.Error(), \"parsing image name\")\n}","tryCatchPattern":"projectID, err := gcp.ExtractProjectID(imageName)\nif err != nil {\n    if strings.Contains(err.Error(), \"parsing image name\") {\n        return fmt.Errorf(\"fix image ref syntax %q: %w\", imageName, err)\n    }\n    return err\n}","preventionTips":["Validate image names with name.ParseReference before calling.","Strip URL schemes and stray characters; use tag-or-digest-qualified refs.","Only call ExtractProjectID for Google registries; pass project ID explicitly otherwise."],"tags":["gcp","image-name","parsing","gcr"],"backgroundTag":"image-reference-parse-failed","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"}