{"record":{"id":"78d88d9e8309e471","repo":"junegunn/fzf","slug":"header-lines-must-be-a-non-negative-integer","errorCode":null,"errorMessage":"header lines must be a non-negative integer","messagePattern":"header lines must be a non-negative integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/options.go","lineNumber":3509,"sourceCode":"\t\t\t} else if match, _ := optString(arg, \"-s\"); match {\n\t\t\t\topts.Sort = 1 // Don't care\n\t\t\t} else if match, value := optString(arg, \"-m\"); match {\n\t\t\t\tif opts.Multi, err = atoi(value); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn errors.New(\"unknown option: \" + arg)\n\t\t\t}\n\t\t}\n\n\t\tif val != nil {\n\t\t\treturn errors.New(\"unexpected value for \" + arg + \": \" + *val)\n\t\t}\n\t}\n\t*index += len(allArgs)\n\n\tif opts.HeaderLines < 0 {\n\t\treturn errors.New(\"header lines must be a non-negative integer\")\n\t}\n\n\tif opts.HscrollOff < 0 {\n\t\treturn errors.New(\"hscroll offset must be a non-negative integer\")\n\t}\n\n\tif opts.ScrollOff < 0 {\n\t\treturn errors.New(\"scroll offset must be a non-negative integer\")\n\t}\n\n\tif opts.Tabstop < 1 {\n\t\treturn errors.New(\"tab stop must be a positive integer\")\n\t}\n\n\tif len(opts.JumpLabels) == 0 {\n\t\treturn errors.New(\"empty jump labels\")\n\t}\n","sourceCodeStart":3491,"sourceCodeEnd":3527,"githubUrl":"https://github.com/junegunn/fzf/blob/bd4efa277b49ef34ca4025bff9b1a288e1980eff/src/options.go#L3491-L3527","documentation":"fzf validates that --headerlines is not negative after option parsing completes. HeaderLines counts lines taken from the top of the input to display as a sticky header, so a negative count is meaningless.","triggerScenarios":"Passing --headerlines=-1 or a negative value computed by a script (e.g. --headerlines=$((n-2)) when n < 2). The post-parse check at options.go:3509 rejects opts.HeaderLines < 0.","commonSituations":"Shell arithmetic producing negative counts (empty files, off-by-one); reusing a header-lines value from another context where 0/negative meant 'auto'.","solutions":["Fix the arithmetic so the value is 0 or positive","If the value is dynamic, clamp it: max(0, n)","Remember 0 means 'no header lines', not negative"],"exampleFix":"# before\nfzf --headerlines=$(( count - 2 ))\n# after\nfzf --headerlines=$(( count > 2 ? count - 2 : 0 ))","handlingStrategy":"validation","validationCode":"// Shell: clamp header lines\nhl=$(( n > 2 ? n - 2 : 0 ))\nexec fzf --headerlines=\"$hl\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp any computed header-lines to max(0, n)","Treat 0 as the 'none' sentinel instead of negative numbers","Dry-run wrappers against empty inputs where counters go negative"],"tags":["fzf","cli","validation","header"],"backgroundTag":null,"analyzedSha":"bd4efa277b49ef34ca4025bff9b1a288e1980eff","analyzedAt":"2026-08-15T06:11:46.983Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}