alibaba/open-code-review · error
invalid %s for %s: %q contains whitespace
Error message
invalid %s for %s: %q contains whitespace
What it means
normalizeAWSSetting validates values for aws_region/aws_profile. After trimming, an empty value is allowed (clears the field), but any remaining whitespace (spaces, tabs, newlines) inside the value is rejected, since AWS region names and profile names can never contain whitespace. The error names the field, provider key, and the offending raw value.
Source
Thrown at cmd/opencodereview/config_cmd.go:719
func providerAcceptsAWSSettings(providerName string, entry *ProviderEntry) bool {
if entry.Protocol != "" {
return llm.NormalizeProtocol(entry.Protocol) == llm.ProtocolAnthropicBedrock
}
preset, isPreset := llm.LookupProvider(providerName)
return isPreset && preset.AmbientAuth
}
// normalizeAWSSetting trims the value and rejects the shapes AWS itself will
// not accept. Region names are deliberately not checked against a fixed list:
// AWS adds regions faster than any embedded list stays correct, and a wrong one
// already surfaces at request time.
func normalizeAWSSetting(field, key, value string) (string, error) {
trimmed := strings.TrimSpace(value)
if trimmed == "" {
return "", nil // clearing the field hands the decision back to the AWS chain
}
if strings.ContainsAny(trimmed, " \t\n") {
return "", fmt.Errorf("invalid %s for %s: %q contains whitespace", field, key, value)
}
return trimmed, nil
}
func parseModelListValue(value string) ([]string, error) {
value = strings.TrimSpace(value)
if value == "" {
return nil, nil
}
if strings.HasPrefix(value, "[") {
var models []string
if err := json.Unmarshal([]byte(value), &models); err == nil {
return normalizeModelList(models), nil
}
value = strings.TrimSpace(strings.TrimSuffix(strings.TrimPrefix(value, "["), "]"))
}
View on GitHub (pinned to 5cf97d0d15)
Solutions
- Correct the value to a whitespace-free identifier, e.g. us-east-1
- Quote the argument in the shell to avoid word-splitting
- Pass an empty value ('') to clear the field and defer to the AWS credential chain
Example fix
// before ocr config set providers.foo.aws_region "us east 1" // after ocr config set providers.foo.aws_region "us-east-1"
Defensive patterns
Strategy: validation
Validate before calling
v="us-east-1" [[ "$v" =~ [[:space:]] ]] && echo "contains whitespace" || ocr config set providers.foo.aws_region "$v"
Try / catch
trimmed := strings.TrimSpace(value)
if strings.ContainsAny(trimmed, " \t\n") {
return fmt.Errorf("invalid %s for %s: %q contains whitespace", field, key, value)
} Prevention
- AWS regions/profiles are whitespace-free identifiers
- Quote values to prevent shell word-splitting
- Pass an empty value to clear the field rather than a space
When it happens
Trigger: `ocr config set providers.<name>.aws_region "us east 1"` or a value with a trailing unquoted space plus interior whitespace, e.g. "us-east-1 " won't trigger (trimmed), but "us east-1" or a newline-pasted value will.
Common situations: Pasting a multi-line value from a terminal; typing 'us east 1' instead of 'us-east-1'; shell word-splitting injecting spaces into the value.
Related errors
- invalid max_tokens %q: must be a positive integer
- llm.protocol cannot be %q: bedrock derives its host from aws
- unknown config key: %s Supported keys: %s Provider fields: a
- invalid URL for %s: %w
- invalid model list for %s: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/b629b30ffcf1f585.
Report an issue: GitHub.