{"record":{"id":"7e705956aad11c9d","repo":"hashicorp/terraform","slug":"architecture-portion-must-not-contain-whitespace","errorCode":null,"errorMessage":"architecture portion must not contain whitespace","messagePattern":"architecture portion must not contain whitespace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/getproviders/types.go","lineNumber":126,"sourceCode":"\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//\n// If attempting to install providers for use on the same system where the\n// installation process is running, this is the right platform to use.\nvar CurrentPlatform = Platform{\n\tOS:   runtime.GOOS,\n\tArch: runtime.GOARCH,\n}\n\n// PackageMeta represents the metadata related to a particular downloadable","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/getproviders/types.go#L108-L144","documentation":"Returned by ParsePlatform (internal/getproviders/types.go:126) when the architecture segment (the part after the underscore) contains space/tab/newline/CR, detected via strings.ContainsAny(arch, \" \\t\\n\\r\"). Symmetric to the OS check; it ensures the ARCH component is a clean token before building a Platform value used in mirror paths and registry queries.","triggerScenarios":"Calling ParsePlatform on a string like \"linux_am d64\", \"linux_amd64\\n\", or a value where the arch portion was concatenated from a list/slice that introduced whitespace.","commonSituations":"Joining a slice to form the arch with strings.Join(\" \") instead of \"\", arch values read from files with trailing newlines, user-typed platform specifiers with spaces, or templating bugs that append a trailing separator.","solutions":["Source the arch portion from runtime.GOARCH or a fixed allow-list (amd64, arm64, arm, 386, darwin variants).","Trim whitespace from the arch segment before calling ParsePlatform.","Validate the segment against ^\\S+$ and a known arch set before parsing.","Fix upstream concatenation that introduces spaces (use strings.Join with empty separator)."],"exampleFix":"// before\narch := strings.Join([]string{\"amd\", \"64\"}, \" \")  // \"amd 64\"\np, err := ParsePlatform(\"linux_\" + arch)  // -> architecture portion must not contain whitespace\n\n// after\narch := strings.Join([]string{\"amd\", \"64\"}, \"\")  // \"amd64\"\np, err := ParsePlatform(\"linux_\" + arch)","handlingStrategy":"validation","validationCode":"func archSegmentClean(s string) bool {\n    parts := strings.SplitN(s, \"_\", 2)\n    if len(parts) != 2 { return false }\n    return !strings.ContainsAny(parts[1], \" \\t\\n\\r\")\n}","typeGuard":"var knownArch = map[string]bool{\"amd64\":true,\"arm64\":true,\"arm\":true,\"386\":true}\nfunc archIsKnown(s string) bool {\n    parts := strings.SplitN(s, \"_\", 2)\n    return len(parts) == 2 && knownArch[parts[1]]\n}","tryCatchPattern":"p, err := getproviders.ParsePlatform(raw)\nif err != nil && strings.Contains(err.Error(), \"architecture portion\") {\n    raw = strings.TrimSpace(strings.TrimRight(raw, \" \\t\\n\\r\"))\n    p, err = getproviders.ParsePlatform(raw)\n}","preventionTips":["Source arch from runtime.GOARCH or an allow-list.","Never use strings.Join(..., \" \") to build the arch segment.","Trim trailing whitespace from file-sourced identifiers.","Validate arch against a known set before parsing."],"tags":["platform","parsing","provider","validation","whitespace"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}