{"record":{"id":"2a7aa344f85f1a79","repo":"go-delve/delve","slug":"invalid-frame-d","errorCode":null,"errorMessage":"Invalid frame %d","messagePattern":"Invalid frame (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/command.go","lineNumber":1042,"sourceCode":"\t\tif frame, err = strconv.Atoi(args[0]); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif len(args) > 1 {\n\t\t\targ = args[1]\n\t\t}\n\t}\n\tswitch direction {\n\tcase frameUp:\n\t\tframe = c.frame + frame\n\tcase frameDown:\n\t\tframe = c.frame - frame\n\t}\n\tif len(arg) > 0 {\n\t\tctx.Scope.Frame = frame\n\t\treturn c.CallWithContext(arg, t, ctx)\n\t}\n\tif frame < 0 {\n\t\treturn fmt.Errorf(\"Invalid frame %d\", frame)\n\t}\n\tstack, err := t.client.Stacktrace(ctx.Scope.GoroutineID, frame, frame, 0, nil)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif len(stack) == 0 {\n\t\treturn fmt.Errorf(\"Invalid frame %d\", frame)\n\t}\n\tc.frame = frame\n\tstate, err := t.client.GetState()\n\tif err != nil {\n\t\treturn err\n\t}\n\tprintcontext(t, state)\n\tth := stack[0]\n\tfmt.Fprintf(t.stdout, \"Frame %d: %s:%d (PC: %x)\\n\", frame, t.formatPath(th.File), th.Line, th.PC)\n\tprintfile(t, th.File, th.Line, true)\n\treturn nil","sourceCodeStart":1024,"sourceCodeEnd":1060,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/command.go#L1024-L1060","documentation":"The terminal's frame command switches the current stack frame (frame <n> [command]). When a negative frame number is supplied, the debugger client is never queried; the command rejects it immediately with 'Invalid frame %d'. Frames are zero-based and only non-negative indices are meaningful.","triggerScenarios":"Running `frame -1` or any negative-numbered frame command in the Delve CLI (or via the terminal command interface), without a trailing command argument (arg is empty), so the frame < 0 guard fires.","commonSituations":"Typing negative frame indices expecting Python-like negative indexing (counting from the innermost/top frame backwards); scripts computing frame offsets that underflow to negative values.","solutions":["Use a non-negative frame index; frames start at 0 (the innermost/current frame).","If you want a frame relative to the top of the stack, compute the absolute index from a stacktrace first.","Note: `frame -1 <cmd>` with an argument skips this guard (it forwards to CallWithContext), but valid frame selection still requires index >= 0."],"exampleFix":"# before\nframe -1\n# after\nframe 0   # or pick a valid index from the stacktrace output","handlingStrategy":"validation","validationCode":"if frame < 0 {\n    return fmt.Errorf(\"frame index must be >= 0, got %d\", frame)\n}","typeGuard":"func isValidFrameIndex(n int) bool { return n >= 0 }","tryCatchPattern":"if err := cmd.Call(\"frame -1\"); err != nil {\n    if strings.HasPrefix(err.Error(), \"Invalid frame\") {\n        // prompt user to use a non-negative index\n    }\n    return err\n}","preventionTips":["Frame indices are zero-based and non-negative — never use negative indexing.","Fetch the stacktrace first and clamp the frame index to len(stack)-1.","Avoid computing frame indices with arithmetic that can underflow.","Document that Delve does not support negative (reverse) frame indices like some debuggers."],"tags":["terminal","cli","stackframe","input-validation"],"backgroundTag":"invalid-frame-index","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}