{"record":{"id":"3ceca00c5f4272fb","repo":"go-delve/delve","slug":"internal-debugger-error-depth-check-failed-depth","errorCode":null,"errorMessage":"internal debugger error: depth check failed: depth at the end is not %d (got %d)\n%s","messagePattern":"internal debugger error: depth check failed: depth at the end is not (.+?) \\(got (.+?)\\)\n(.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/evalop/evalcompile.go","lineNumber":288,"sourceCode":"\t\td := depth[i] - npop + npush\n\t\tcheckAndSet(i+1, d)\n\t\tswitch op := op.(type) {\n\t\tcase *Jump:\n\t\t\tcheckAndSet(op.Target, d)\n\t\tcase *CallInjectionStartSpecial:\n\t\t\tdebugPinnerSeen = true\n\t\tcase *CallInjectionComplete:\n\t\t\tif op.DoPinning && !debugPinnerSeen {\n\t\t\t\terr = fmt.Errorf(\"internal debugger error: pinning call injection seen before call to %s at instruction %d\", DebugPinnerFunctionName, i)\n\t\t\t}\n\t\t}\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tif depth[len(ctx.ops)] != endDepth {\n\t\treturn fmt.Errorf(\"internal debugger error: depth check failed: depth at the end is not %d (got %d)\\n%s\", depth[len(ctx.ops)], endDepth, Listing(depth, ctx.ops))\n\t}\n\treturn nil\n}\n\nfunc (ctx *compileCtx) compileAST(t ast.Expr, toplevel bool) error {\n\tswitch node := t.(type) {\n\tcase *ast.CallExpr:\n\t\tif f, ok := node.Fun.(*ast.SelectorExpr); ok && ctx.flags&BreakpointCondition != 0 {\n\t\t\tconst catch = \"catch\"\n\t\t\tif ident, ok := f.X.(*ast.Ident); ok && ident.Name == DelvePackage && f.Sel.Name == catch {\n\t\t\t\tif !toplevel {\n\t\t\t\t\treturn fmt.Errorf(\"%s.%s can only be used at toplevel\", DelvePackage, catch)\n\t\t\t\t}\n\t\t\t\tif len(node.Args) != 1 {\n\t\t\t\t\treturn fmt.Errorf(\"wrong number of arguments for %s.%s\", DelvePackage, catch)\n\t\t\t\t}\n\t\t\t\tctx.pushOp(&DisableErrors{})\n\t\t\t\treturn ctx.compileAST(node.Args[0], false)","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/evalop/evalcompile.go#L270-L306","documentation":"Final check of the expression compiler's depth verification (depthCheck in pkg/proc/evalop/evalcompile.go): after compiling the whole expression, the operand stack depth must equal `endDepth` (normally 1 result for an evaluation, per CompileAST/CompileSet); a different depth means the compiled program does not produce the expected number of results. Like the other depth checks, it flags a compiler bug, not user input problems.","triggerScenarios":"CompileAST or CompileSet on an expression whose compiled ops leave a different number of values on the stack than required — e.g. an opcode pushes/pops asymmetrically due to a compile bug in an untested expression construct.","commonSituations":"Appears after delve regressions in the evalop VM, when testing pre-release delve versions, or when expressions combine rare features (casts, delve.catch, call injection) whose opcode emission doesn't balance the stack.","solutions":["Update delve to the latest stable release","Rewrite the failing expression as simpler separate evaluations","Report the reproducing expression and error listing to go-delve/delve"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"depth at the end is not\") {\n    // compiler produced unbalanced stack: simplify and retry\n    return evalSplit(expr)\n}","preventionTips":["Upgrade delve before using advanced expression features","Prefer several simple print expressions over one large compound expression","Report reproducing expressions upstream with the embedded Listing"],"tags":["debugger","internal","compiler","stack-depth","evalop"],"backgroundTag":"internal-invariant-violation","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}