hashicorp/nomad · error
stdin is not supported
Error message
stdin is not supported
What it means
When a KVBuilder argument is exactly '-', the builder reads the whole value from stdin. This error is thrown when the KVBuilder's Stdin field was never set, so there is no reader to consume. The library refuses to guess or fall back to os.Stdin implicitly.
Source
Thrown at command/var.go:210
// Regardless of validity, make sure we make our result
if b.result == nil {
b.result = make(map[string]any)
}
// Empty strings are fine, just ignored
if raw == "" {
return nil
}
// Split into key/value
parts := strings.SplitN(raw, "=", 2)
// If the arg is exactly "-", then we need to read from stdin
// and merge the results into the resulting structure.
if len(parts) == 1 {
if raw == "-" {
if b.Stdin == nil {
return fmt.Errorf("stdin is not supported")
}
if b.stdin {
return fmt.Errorf("stdin already consumed")
}
b.stdin = true
return b.addReader(b.Stdin)
}
// If the arg begins with "@" then we need to read a file directly
if raw[0] == '@' {
f, err := os.Open(raw[1:])
if err != nil {
return err
}
defer f.Close()
return b.addReader(f)View on GitHub (pinned to 482b49bf1a)
Solutions
- Set the Stdin field on KVBuilder before calling Add, e.g. b.Stdin = os.Stdin (or a bytes.Buffer with your JSON payload)
- If no stdin input is intended, pass an explicit key=value pair instead of '-'
- In tests, assign a strings.Reader or bytes.Buffer to Stdin to simulate piped input
Example fix
// before
b := &KVBuilder{Result: map[string]interface{}{}}
b.Add("-")
// after
b := &KVBuilder{Result: map[string]interface{}{}, Stdin: strings.NewReader(`{"key":"value"}`)}
b.Add("-") Defensive patterns
Strategy: validation
Validate before calling
if b.Stdin == nil && containsDashArg(args) {
b.Stdin = os.Stdin // or strings.NewReader(jsonPayload)
} Prevention
- Always populate KVBuilder.Stdin when constructing it programmatically
- Avoid '-' arguments outside real CLI contexts; pass explicit key=value instead
- Use bytes.Buffer/strings.Reader in tests to simulate stdin
When it happens
Trigger: Calling KVBuilder.Add("-") (or var CLI with a lone '-') on a builder constructed without assigning b.Stdin — typically when the builder is used programmatically outside the normal CLI wiring.
Common situations: Embedding the var parser in tests or other tools where Stdin is left nil; refactors that construct KVBuilder directly instead of through the command plumbing that wires os.Stdin in.
Related errors
- Error loading configuration from %s: %s
- unable to parse configured address: %v
- Unable to parse configured address: %v
- stdin already consumed
- No nomad log file defined
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/af00b70318086087.
Report an issue: GitHub.