{"record":{"id":"04f08a1b252bd760","repo":"go-delve/delve","slug":"invalid-next-count","errorCode":null,"errorMessage":"Invalid next count","messagePattern":"Invalid next count","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/command.go","lineNumber":1545,"sourceCode":"func (c *Commands) next(t *Term, ctx callContext, args string) error {\n\tif err := scopePrefixSwitch(t, ctx); err != nil {\n\t\treturn err\n\t}\n\tif c.frame != 0 {\n\t\treturn errNotOnFrameZero\n\t}\n\n\tnextfn := t.client.Next\n\tif ctx.Prefix == revPrefix {\n\t\tnextfn = t.client.ReverseNext\n\t}\n\n\tvar count int64\n\tvar err error\n\tif count, err = parseOptionalCount(args); err != nil {\n\t\treturn err\n\t} else if count <= 0 {\n\t\treturn errors.New(\"Invalid next count\")\n\t}\n\tfor ; count > 0; count-- {\n\t\tstate, err := exitedToError(nextfn())\n\t\tif err != nil {\n\t\t\tprintcontextNoState(t)\n\t\t\treturn err\n\t\t}\n\t\t// If we're about the exit the loop, print the context.\n\t\tfinishedNext := count == 1\n\t\tif finishedNext {\n\t\t\tprintcontext(t, state)\n\t\t}\n\t\tif err := continueUntilCompleteNext(t, state, \"next\", finishedNext); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}","sourceCodeStart":1527,"sourceCodeEnd":1563,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/command.go#L1527-L1563","documentation":"The 'next' command accepts an optional repeat count so 'next 5' performs five next operations. This error is returned when the parsed count is zero or negative, since stepping a non-positive number of times is meaningless. parseOptionalCount accepts an empty argument (defaulting to 1) but any explicit value must be >= 1.","triggerScenarios":"Running 'next 0' or 'next -3': parseOptionalCount succeeds but the `count <= 0` check returns 'Invalid next count' (pkg/terminal/command.go:1545).","commonSituations":"Scripted stepping loops that compute a zero count; users confusing 0-based vs 1-based counts; typos like 'next -1' intending 'reverse next' (which is 'rev next').","solutions":["Use a positive count, e.g. 'next 5'","Omit the argument entirely for a single step ('next')","Use 'rev next N' for reverse stepping instead of a negative count"],"exampleFix":"// before\nnext 0\n// after\nnext","handlingStrategy":"validation","validationCode":"n, err := strconv.ParseInt(arg, 10, 64)\nif arg != \"\" && (err != nil || n <= 0) {\n\treturn errors.New(\"next count must be a positive integer\")\n}","typeGuard":null,"tryCatchPattern":"if err := next(...); err != nil && strings.Contains(err.Error(), \"Invalid next count\") { /* clamp count to >= 1 and retry */ }","preventionTips":["Never pass 0 or negative counts to next","Use 'rev next' for reverse stepping, not negative counts","Guard scripted loop counters that compute the repeat count"],"tags":["terminal","stepping","cli-usage"],"backgroundTag":"invalid-argument-value","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}