{"record":{"id":"0aa4b08f9ee22a36","repo":"googleapis/mcp-toolbox","slug":"invalid-s-q-must-match-s","errorCode":null,"errorMessage":"invalid %s %q: must match %s","messagePattern":"invalid (.+?) %q: must match (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/cloudsqlconnect/inputvalidate.go","lineNumber":64,"sourceCode":"\t}\n\tif !projectIDRe.MatchString(project) {\n\t\treturn \"\", \"\", \"\", fmt.Errorf(\"invalid project ID %q: must match %s\", project, projectIDRe)\n\t}\n\tif !gcpRegionRe.MatchString(region) {\n\t\treturn \"\", \"\", \"\", fmt.Errorf(\"invalid region %q: must match %s\", region, gcpRegionRe)\n\t}\n\tif !cloudSQLInstanceRe.MatchString(instance) {\n\t\treturn \"\", \"\", \"\", fmt.Errorf(\"invalid Cloud SQL instance ID %q: must match %s\", instance, cloudSQLInstanceRe)\n\t}\n\treturn project, region, instance, nil\n}\n\n// ValidateGCEResourceName checks a VM name or zone name against the standard\n// GCE resource-name rule (lowercase, digits, hyphen; must start with a letter\n// and not end with a hyphen, max 63 chars).\nfunc ValidateGCEResourceName(name, kind string) error {\n\tif !gceResourceRe.MatchString(name) {\n\t\treturn fmt.Errorf(\"invalid %s %q: must match %s\", kind, name, gceResourceRe)\n\t}\n\treturn nil\n}\n\n// ValidateDatabaseName accepts the conservative subset of database identifier\n// characters that's safe in DSNs and code-snippet templates across Postgres,\n// MySQL and SQL Server. It deliberately rejects quotes, semicolons, and\n// whitespace even when the engine itself would accept them.\nfunc ValidateDatabaseName(name string) error {\n\tif !databaseNameRe.MatchString(name) {\n\t\treturn fmt.Errorf(\"invalid database_name %q: must match %s\", name, databaseNameRe)\n\t}\n\treturn nil\n}\n","sourceCodeStart":46,"sourceCodeEnd":79,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/util/cloudsqlconnect/inputvalidate.go#L46-L79","documentation":"ValidateGCEResourceName checks a VM name or zone name against the GCE resource-name rule ^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$: lowercase letters, digits, and hyphens; must start with a letter, must not end with a hyphen, max 63 chars. The failing value is echoed in the message along with the kind ('vm', 'zone', etc.) supplied by the caller.","triggerScenarios":"Calling FindVM-related tool flows (via Invoke) with a vm_name or vm_zone containing uppercase letters, underscores, spaces, a leading digit, or a trailing hyphen.","commonSituations":"VM names copied from cloud consoles of other providers; CamelCase names like 'MyVM'; zone typed as 'us_central1_a'; accidental trailing whitespace or hyphen from copy-paste.","solutions":["Convert the name to lowercase and replace underscores with hyphens","Ensure it starts with a letter and ends with a letter or digit, and is at most 63 characters","Verify the actual resource name with `gcloud compute instances list` or `gcloud compute zones list`"],"exampleFix":"// before\nValidateGCEResourceName(\"My_VM_01\", \"vm\")\n// after\nValidateGCEResourceName(\"my-vm-01\", \"vm\")","handlingStrategy":"validation","validationCode":"var gceResourceRe = regexp.MustCompile(`^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`)\nif err := cloudsqlconnect.ValidateGCEResourceName(vmName, \"vm\"); err != nil {\n    return err\n}\nif err := cloudsqlconnect.ValidateGCEResourceName(zone, \"zone\"); err != nil {\n    return err\n}","typeGuard":"func isValidGCEResource(name string) bool {\n    return regexp.MustCompile(`^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`).MatchString(name)\n}","tryCatchPattern":"if err := cloudsqlconnect.ValidateGCEResourceName(name, kind); err != nil {\n    return fmt.Errorf(\"%w (GCE names: lowercase letters/digits/hyphens, start with a letter, max 63 chars)\", err)\n}","preventionTips":["Normalize names to lowercase and replace underscores before passing them in","Reject uppercase/underscored names at the config or flag level","Trim whitespace from copy-pasted names"],"tags":["gcp","compute-engine","validation"],"backgroundTag":"input-validation-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}