{"record":{"id":"adb5821ae48ea90f","repo":"go-delve/delve","slug":"internal-debugger-error-wrong-stack-size-at-end","errorCode":null,"errorMessage":"internal debugger error: wrong stack size at end %d","messagePattern":"internal debugger error: wrong stack size at end (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":1088,"sourceCode":"\t\t}\n\t\tstack.lastRetiredFncall = fncall\n\t\t// Resume target to undo one call\n\t\tstack.callInjectionContinue = true\n\t\tscope.callCtx.injectionThread = nil\n\t\treturn\n\t}\n}\n\nfunc (stack *evalStack) result(cfg *LoadConfig) (*Variable, error) {\n\tvar r *Variable\n\tswitch len(stack.stack) {\n\tcase 0:\n\t\t// ok\n\tcase 1:\n\t\tr = stack.peek()\n\tdefault:\n\t\tif stack.err == nil {\n\t\t\tstack.err = fmt.Errorf(\"internal debugger error: wrong stack size at end %d\", len(stack.stack))\n\t\t}\n\t}\n\tif r != nil && cfg != nil && stack.err == nil {\n\t\tr.loadValue(*cfg)\n\t}\n\treturn r, stack.err\n}\n\n// executeOp executes the opcode at stack.ops[stack.opidx] and increments stack.opidx.\nfunc (stack *evalStack) executeOp() {\n\tscope, ops, curthread := stack.scope, stack.ops, stack.curthread\n\tdefer func() {\n\t\terr := recover()\n\t\tif err != nil {\n\t\t\tlogflags.Bug.Inc()\n\t\t\tstack.err = fmt.Errorf(\"internal debugger error: %v (recovered)\\n%s\", err, string(debug.Stack()))\n\t\t}\n\t}()","sourceCodeStart":1070,"sourceCodeEnd":1106,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L1070-L1106","documentation":"result() unwinds the evalStack after running an evalop program: a well-formed program leaves exactly 0 values (statements) or 1 value (expressions). Any other remaining depth means the compiled op program and the stack machine disagree — an internal invariant violation. The error is attached to the stack instead of returned directly so cleanup paths still run.","triggerScenarios":"EvalExpression, SetVariable, evalAST, evalBreakpointCondition, or finishEvalExpressionWithCalls finishing with the eval stack holding 2+ values — caused by an op sequence pushing more values than it pops, typically due to a compiler/evaluator mismatch in evalop for the given expression shape, or a corrupted/ill-formed expression program.","commonSituations":"Evaluating complex nested expressions that expose an evalop compilation bug; breakpoint conditions compiled differently between versions; custom clients sending unusual expression syntax through the RPC eval APIs; regression after a Delve or Go toolchain upgrade.","solutions":["Report to go-delve/delve with the exact expression/condition — this is a debugger internal invariant violation.","Rewrite the expression in a simpler equivalent form (fewer nested operators, explicit parentheses, intermediate steps via separate evaluations).","Split compound expressions: evaluate sub-expressions individually instead of one large expression.","Test with a stock dlv CLI on the same expression to confirm it's not a client-side query construction bug."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// sanity-check expression shape client-side before submitting\nif strings.Count(expr, \"(\") != strings.Count(expr, \")\") {\n    return errors.New(\"unbalanced parentheses in expression\")\n}","typeGuard":null,"tryCatchPattern":"r, err := scope.EvalExpression(expr, cfg)\nif err != nil && strings.Contains(err.Error(), \"wrong stack size at end\") {\n    // retry with a simplified form of the expression\n    r, err = scope.EvalExpression(simplify(expr), cfg)\n}","preventionTips":["Keep breakpoint conditions and scripted expressions simple; split complex ones into steps","Test expressions against stock dlv CLI before embedding in tooling","Update Delve when upgrading the Go toolchain (evalop changes track compiler behavior)","Report any expression that reproduces this to go-delve/delve — it is an internal invariant bug"],"tags":["go","debugger","eval-stack","internal-error"],"backgroundTag":"eval-stack-invariant-violated","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}