{"record":{"id":"2105af4645157839","repo":"hashicorp/terraform","slug":"must-be-two-words-separated-by-an-underscore","errorCode":null,"errorMessage":"must be two words separated by an underscore","messagePattern":"must be two words separated by an underscore","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/getproviders/types.go","lineNumber":118,"sourceCode":"// The ordering is lexical first by OS and then by Architecture.\n// This ordering is primarily just to ensure that results of\n// functions in this package will be deterministic. The ordering is not\n// intended to have any semantic meaning and is subject to change in future.\nfunc (p Platform) LessThan(other Platform) bool {\n\tswitch {\n\tcase p.OS != other.OS:\n\t\treturn p.OS < other.OS\n\tdefault:\n\t\treturn p.Arch < other.Arch\n\t}\n}\n\n// ParsePlatform parses a string representation of a platform, like\n// \"linux_amd64\", or returns an error if the string is not valid.\nfunc ParsePlatform(str string) (Platform, error) {\n\tparts := strings.Split(str, \"_\")\n\tif len(parts) != 2 {\n\t\treturn Platform{}, fmt.Errorf(\"must be two words separated by an underscore\")\n\t}\n\n\tos, arch := parts[0], parts[1]\n\tif strings.ContainsAny(os, \" \\t\\n\\r\") {\n\t\treturn Platform{}, fmt.Errorf(\"OS portion must not contain whitespace\")\n\t}\n\tif strings.ContainsAny(arch, \" \\t\\n\\r\") {\n\t\treturn Platform{}, fmt.Errorf(\"architecture portion must not contain whitespace\")\n\t}\n\n\treturn Platform{\n\t\tOS:   os,\n\t\tArch: arch,\n\t}, nil\n}\n\n// CurrentPlatform is the platform where the current program is running.\n//","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/getproviders/types.go#L100-L136","documentation":"Returned by ParsePlatform when the input string does not split into exactly two underscore-separated parts. ParsePlatform expects the canonical GOOS_GOARCH form (e.g. 'linux_amd64'); zero underscores or more than one underscore both trip this guard before any whitespace checks run.","triggerScenarios":"A platform string passed to ParsePlatform has 0 underscores ('linuxamd64', 'linux', '') or 2+ underscores ('linux_amd64_arm64', 'a_b_c'). Common entry points: provider target_platform config, CLI flags, decoded registry keys.","commonSituations":"Typing 'linux-amd64' (hyphen instead of underscore); passing an empty string; passing a triple like 'linux_amd64_v1'; misconfigured provider installation target via TF_REGISTRY_* env or config.","solutions":["Use the canonical GOOS_GOARCH form with exactly one underscore, e.g. 'linux_amd64', 'darwin_arm64', 'windows_amd64'.","Confirm the value is not empty and contains no hyphens or extra underscores.","If the value comes from a build flag or env var, validate it against runtime.GOOS/GOARCH known pairs.","Strip any suffix (e.g. '_v1', '_v2') before calling ParsePlatform."],"exampleFix":"// before\nplatform, err := getproviders.ParsePlatform(\"linux-amd64\")\n// after\nplatform, err := getproviders.ParsePlatform(\"linux_amd64\")","handlingStrategy":"validation","validationCode":"// Validate platform string shape before calling ParsePlatform.\nfunc validPlatformShape(s string) bool {\n    parts := strings.Split(s, \"_\")\n    return len(parts) == 2 && parts[0] != \"\" && parts[1] != \"\"\n}","typeGuard":"// Type-ish guard via regex.\nvar platformRe = regexp.MustCompile(`^[a-z0-9]+_[a-z0-9]+$`)\nfunc isValidPlatform(s string) bool { return platformRe.MatchString(s) }","tryCatchPattern":null,"preventionTips":["Canonicalize platform strings to GOOS_GOARCH early in input pipelines.","Reject user-supplied platform strings that fail a regex check.","Document the underscore requirement in config schemas."],"tags":["platform","validation","parsing","getproviders"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}