hashicorp/nomad · error
stdin already consumed
Error message
stdin already consumed
What it means
KVBuilder allows reading from stdin at most once per invocation. Once '-' has been consumed (the unexported stdin flag is set), a second '-' argument triggers this error. It prevents ambiguous double-reads of a non-seekable stream.
Source
Thrown at command/var.go:213
}
// 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
- Pass '-' only once per command invocation; combine remaining vars as explicit key=value pairs
- Merge all JSON input into a single stdin payload read by the one '-'
- If multiple stdin reads are genuinely needed, construct a new KVBuilder with a fresh Stdin reader
Example fix
// before
b.Add("-", "-")
// after
b.Add("-")
b.Add("otherkey=othervalue") Defensive patterns
Strategy: validation
Validate before calling
if n := strings.Count(strings.Join(args, " "), "\"-\"") + countExactDashes(args); n > 1 {
// reject: stdin can only be consumed once
} Prevention
- Use '-' at most once per KVBuilder invocation
- Supply additional variables as key=value or @file references
- Review generated CLI args in loops for repeated '-var -'
When it happens
Trigger: Passing '-' twice to KVBuilder.Add, e.g. Add("-", "-") or two '-var -' flags in one command, after the first '-' successfully consumed Stdin.
Common situations: Shell scripts piping one JSON blob but specifying '-var -' multiple times; loops that append '-var -' per variable when the intent was 'key=-' per pair.
Related errors
- Invalid key value pair for topic: %s
- invalid key/value pair %q: %w
- stdin is not supported
- format must be key=value
- error reading file: %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/6cbab969a3b6a78c.
Report an issue: GitHub.