hashicorp/nomad · error
both -n and -c set
Error message
both -n and -c set
What it means
`nomad alloc logs` accepts either -n (tail N lines) or -c (tail N bytes), but not both, because the offset into the log file cannot be computed two ways at once. handleSingleFile returns this error when both flags were explicitly set on the command line.
Source
Thrown at command/alloc_logs.go:287
return 0
}
func (l *AllocLogsCommand) handleSingleFile(client *api.Client, alloc *api.Allocation, logType string) error {
// We have a file, output it.
var r io.ReadCloser
var readErr error
if !l.tail {
r, readErr = l.followFile(client, alloc, logType, api.OriginStart, 0)
if readErr != nil {
return fmt.Errorf("error reading file: %v", readErr)
}
} else {
// Parse the offset
var offset = defaultTailLines * bytesToLines
if nLines, nBytes := l.numLines != -1, l.numBytes != -1; nLines && nBytes {
return errors.New("both -n and -c set")
} else if nLines {
offset = l.numLines * bytesToLines
} else if nBytes {
offset = l.numBytes
} else {
l.numLines = defaultTailLines
}
r, readErr = l.followFile(client, alloc, logType, api.OriginEnd, offset)
// If numLines is set, wrap the reader
if l.numLines != -1 {
r = NewLineLimitReader(r, int(l.numLines), int(l.numLines*bytesToLines), 1*time.Second)
}
if readErr != nil {
return fmt.Errorf("error tailing file: %v", readErr)
}View on GitHub (pinned to 482b49bf1a)
Solutions
- Remove either -n or -c from the command, keeping only one.
- Default behavior (no flags) tails the default number of lines; use that if you don't need a specific size.
- If scripting, set only one flag conditionally based on the unit the user chose.
Example fix
// before $ nomad alloc logs -n 100 -c 5000 1f2b3c4d // after $ nomad alloc logs -n 100 1f2b3c4d # or: -c 5000, but not both
Defensive patterns
Strategy: validation
Validate before calling
if n != nil && c != nil {
return errors.New("pass only one of -n (lines) or -c (bytes)")
} Try / catch
out, err := runAllocLogs(); if err != nil && strings.Contains(err.Error(), "both -n and -c") {
fmt.Fprintln(os.Stderr, "use -n or -c, not both")
os.Exit(1)
} Prevention
- Validate flag combinations in wrappers around nomad alloc logs.
- Keep only one tail unit in scripts; choose lines or bytes per use case.
- Rely on defaults when no specific size is needed.
When it happens
Trigger: Running `nomad alloc logs -n 100 -c 5000 <alloc>` — both line-count and byte-count tails requested simultaneously.
Common situations: Copy-pasting example commands that include both flags, or scripting where a default -n is combined with a user-supplied -c.
Understand the failure class
Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.
Related errors
- evaluation ID or filter flag required
- Allocation %q is running the following tasks: * %s Please
- The '-template' flag is only valid when using 'go-template'
- A template must be supplied using '-template' when using go-
- Invalid value for "-out"; valid values are [go-template, hcl
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/77548bfac8095ca6.
Report an issue: GitHub.