{"record":{"id":"3d71049aac42a831","repo":"kubernetes/kops","slug":"invalid-google-cloud-url-content-after-name-q","errorCode":null,"errorMessage":"invalid google cloud URL (content after name): %q","messagePattern":"invalid google cloud URL \\(content after name\\): %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/gce/gce_url.go","lineNumber":113,"sourceCode":"\t\t\tparsed.Zone = tokens[pos]\n\t\tcase t == \"regions\" && ((pos + 2) < len(tokens)):\n\t\t\tpos++\n\t\t\tif pos >= len(tokens) {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid google cloud URL (unexpected regions): %q\", u)\n\t\t\t}\n\t\t\tparsed.Region = tokens[pos]\n\t\tcase t == \"global\":\n\t\t\tparsed.Global = true\n\t\tdefault:\n\t\t\tparsed.Type = tokens[pos]\n\t\t\tpos++\n\t\t\tif pos >= len(tokens) {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid google cloud URL (no name): %q\", u)\n\t\t\t}\n\t\t\tparsed.Name = tokens[pos]\n\t\t\tpos++\n\t\t\tif pos != len(tokens) {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid google cloud URL (content after name): %q\", u)\n\t\t\t} else {\n\t\t\t\treturn parsed, nil\n\t\t\t}\n\t\t}\n\t\tpos++\n\t}\n}\n","sourceCodeStart":95,"sourceCodeEnd":121,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/gce/gce_url.go#L95-L121","documentation":"ParseGoogleCloudURL tokenizes a Google Cloud compute resource URL path segment by segment. Once it reaches the resource type token (e.g. disks, instances), it consumes exactly one name token and expects the token list to end. This error is thrown when there are extra path segments after the resource name, meaning the URL does not point to a single named resource.","triggerScenarios":"Passing a URL with trailing path content after the resource name to ParseGoogleCloudURL, e.g. https://www.googleapis.com/compute/v1/projects/p/zones/z/disks/disk-a/extra, a URL for a nested sub-resource, a double slash producing an empty extra token, or a URL with a trailing slash.","commonSituations":"Dumping cluster state or listing/deleting GCE resources (disks, target pools, forwarding rules, HTTP health checks) when a stored or hand-written self-link is malformed, copied from a sub-resource endpoint, or has a stray trailing slash.","solutions":["Print/inspect the offending URL and remove any path segments after the resource name (including trailing slashes).","Regenerate the self-link from the API object's SelfLink field rather than constructing it manually.","If parsing a list-style or aggregated URL, use the appropriate list API call instead of ParseGoogleCloudURL.","Check for double slashes or typos in project/zone segments that shift token positions."],"exampleFix":"// before\nu := \"https://www.googleapis.com/compute/v1/projects/myproj/zones/us-central1-a/disks/mydisk/\"\n_, err := gce.ParseGoogleCloudURL(u)\n// after\nu := \"https://www.googleapis.com/compute/v1/projects/myproj/zones/us-central1-a/disks/mydisk\"\n_, err := gce.ParseGoogleCloudURL(u)","handlingStrategy":"validation","validationCode":"// validate the URL shape before parsing\nfunc validResourceURL(u string) bool {\n\tparsed, err := url.Parse(u)\n\tif err != nil || parsed.Path == \"\" {\n\t\treturn false\n\t}\n\tsegs := strings.Split(strings.Trim(parsed.Path, \"/\"), \"/\")\n\treturn len(segs) >= 2 && segs[len(segs)-2] != \"\" && segs[len(segs)-1] != \"\"\n}\nif !validResourceURL(selfLink) {\n\treturn fmt.Errorf(\"not a single-resource URL: %q\", selfLink)\n}\nparsed, err := gce.ParseGoogleCloudURL(selfLink)","typeGuard":"func isGoogleComputeSelfLink(s string) bool {\n\treturn strings.HasPrefix(s, \"https://www.googleapis.com/compute/v1/\") || strings.HasPrefix(s, \"https://www.googleapis.com/compute/beta/\")\n}","tryCatchPattern":null,"preventionTips":["Always take self-links from the API object's SelfLink field, never hand-construct or concatenate them.","Trim trailing slashes before parsing.","Store resource name/project/zone separately instead of round-tripping through URLs."],"tags":["gce","url-parsing","validation"],"backgroundTag":"invalid-resource-url","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}