{"record":{"id":"77548bfac8095ca6","repo":"hashicorp/nomad","slug":"both-n-and-c-set","errorCode":null,"errorMessage":"both -n and -c set","messagePattern":"both -n and -c set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/alloc_logs.go","lineNumber":287,"sourceCode":"\n\treturn 0\n}\n\nfunc (l *AllocLogsCommand) handleSingleFile(client *api.Client, alloc *api.Allocation, logType string) error {\n\t// We have a file, output it.\n\tvar r io.ReadCloser\n\tvar readErr error\n\tif !l.tail {\n\t\tr, readErr = l.followFile(client, alloc, logType, api.OriginStart, 0)\n\t\tif readErr != nil {\n\t\t\treturn fmt.Errorf(\"error reading file: %v\", readErr)\n\t\t}\n\t} else {\n\t\t// Parse the offset\n\t\tvar offset = defaultTailLines * bytesToLines\n\n\t\tif nLines, nBytes := l.numLines != -1, l.numBytes != -1; nLines && nBytes {\n\t\t\treturn errors.New(\"both -n and -c set\")\n\t\t} else if nLines {\n\t\t\toffset = l.numLines * bytesToLines\n\t\t} else if nBytes {\n\t\t\toffset = l.numBytes\n\t\t} else {\n\t\t\tl.numLines = defaultTailLines\n\t\t}\n\n\t\tr, readErr = l.followFile(client, alloc, logType, api.OriginEnd, offset)\n\n\t\t// If numLines is set, wrap the reader\n\t\tif l.numLines != -1 {\n\t\t\tr = NewLineLimitReader(r, int(l.numLines), int(l.numLines*bytesToLines), 1*time.Second)\n\t\t}\n\n\t\tif readErr != nil {\n\t\t\treturn fmt.Errorf(\"error tailing file: %v\", readErr)\n\t\t}","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/alloc_logs.go#L269-L305","documentation":"`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.","triggerScenarios":"Running `nomad alloc logs -n 100 -c 5000 <alloc>` — both line-count and byte-count tails requested simultaneously.","commonSituations":"Copy-pasting example commands that include both flags, or scripting where a default -n is combined with a user-supplied -c.","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."],"exampleFix":"// before\n$ nomad alloc logs -n 100 -c 5000 1f2b3c4d\n// after\n$ nomad alloc logs -n 100 1f2b3c4d   # or: -c 5000, but not both","handlingStrategy":"validation","validationCode":"if n != nil && c != nil {\n    return errors.New(\"pass only one of -n (lines) or -c (bytes)\")\n}","typeGuard":null,"tryCatchPattern":"out, err := runAllocLogs(); if err != nil && strings.Contains(err.Error(), \"both -n and -c\") {\n    fmt.Fprintln(os.Stderr, \"use -n or -c, not both\")\n    os.Exit(1)\n}","preventionTips":["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."],"tags":["cli","flags","logs","argument-validation"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}