hashicorp/terraform · error
OS portion must not contain whitespace
Error message
OS portion must not contain whitespace
What it means
Returned by ParsePlatform (internal/getproviders/types.go:123) when the OS segment (the part before the underscore) contains any of space/tab/newline/CR, detected via strings.ContainsAny(os, " \t\n\r"). It guards against platform identifiers that have the right underscore count but a polluted OS component that would later break filesystem paths or registry lookups.
Source
Thrown at internal/getproviders/types.go:123
switch {
case p.OS != other.OS:
return p.OS < other.OS
default:
return p.Arch < other.Arch
}
}
// ParsePlatform parses a string representation of a platform, like
// "linux_amd64", or returns an error if the string is not valid.
func ParsePlatform(str string) (Platform, error) {
parts := strings.Split(str, "_")
if len(parts) != 2 {
return Platform{}, fmt.Errorf("must be two words separated by an underscore")
}
os, arch := parts[0], parts[1]
if strings.ContainsAny(os, " \t\n\r") {
return Platform{}, fmt.Errorf("OS portion must not contain whitespace")
}
if strings.ContainsAny(arch, " \t\n\r") {
return Platform{}, fmt.Errorf("architecture portion must not contain whitespace")
}
return Platform{
OS: os,
Arch: arch,
}, nil
}
// CurrentPlatform is the platform where the current program is running.
//
// If attempting to install providers for use on the same system where the
// installation process is running, this is the right platform to use.
var CurrentPlatform = Platform{
OS: runtime.GOOS,
Arch: runtime.GOARCH,View on GitHub (pinned to c9def3e214)
Solutions
- Trim surrounding/internal whitespace from the input before calling ParsePlatform, or reject it.
- Source the OS portion from runtime.GOOS / a controlled constant rather than free-form text.
- Validate with regexp ^\S+$ against the OS segment before parsing.
- Sanitize config readers (CSV parsers, file reads) for stray tabs/newlines.
Example fix
// before
p, err := ParsePlatform("lin ux_amd64") // -> OS portion must not contain whitespace
// after
str := strings.TrimSpace(rawStr)
str = strings.Map(func(r rune) rune {
if r == ' ' || r == '\t' || r == '\n' || r == '\r' { return -1 }
return r
}, str)
p, err := ParsePlatform(str) Defensive patterns
Strategy: validation
Validate before calling
func cleanPlatformString(s string) string {
return strings.Map(func(r rune) rune {
if r == ' ' || r == '\t' || r == '\n' || r == '\r' { return -1 }
return r
}, s)
}
// then ParsePlatform(cleanPlatformString(raw)) Type guard
func osSegmentClean(s string) bool {
parts := strings.SplitN(s, "_", 2)
if len(parts) != 2 { return false }
return !strings.ContainsAny(parts[0], " \t\n\r")
} Try / catch
p, err := getproviders.ParsePlatform(raw)
if err != nil && strings.Contains(err.Error(), "OS portion") {
raw = cleanPlatformString(raw)
p, err = getproviders.ParsePlatform(raw)
} Prevention
- Always strings.TrimSpace config-sourced strings before parsing.
- Source OS from runtime.GOOS or a constant, not free text.
- Validate segments against ^\S+$ at the boundary.
- Scan config files for stray tabs/newlines during ingestion.
When it happens
Trigger: Calling ParsePlatform on a string like "lin ux_amd64", "linux\tamd64", or a value read from a config/lock file that got line-break contamination (e.g. a value spanning two lines).
Common situations: Copy-paste of platform identifiers with stray spaces, values ingested from CSV/YAML that retained trailing whitespace, Windows CR/LF line endings leaking into a Linux-built binary's runtime.GOOS-derived string, or shell word-splitting bugs that inject spaces.
Related errors
- architecture portion must not contain whitespace
- must be two words separated by an underscore
- Attempted to initialize pluggable state with an empty string
- ErrInvalidSHA256Hash
- must be eight hexadecimal digits
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/65f69fcaa65bc313.
Report an issue: GitHub.