{"record":{"id":"2f6a0494a266a95e","repo":"go-delve/delve","slug":"error-evaluating-expression-v","errorCode":null,"errorMessage":"error evaluating expression: %v","messagePattern":"error evaluating expression: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/breakpoints.go","lineNumber":515,"sourceCode":"\t\tscope, err = ThreadScope(tgt, thread)\n\t\tif err != nil {\n\t\t\treturn true, err\n\t\t}\n\t}\n\tflags := scope.evalopFlags()\n\tflags |= evalop.BreakpointCondition\n\tops, err := evalop.CompileAST(scopeToEvalLookup{scope}, cond, flags)\n\tif err != nil {\n\t\treturn true, err\n\t}\n\tstack := &evalStack{}\n\tstack.eval(scope, ops)\n\tv, err := stack.result(nil)\n\tif err != nil {\n\t\tif stack.disabledErrors {\n\t\t\treturn false, nil\n\t\t}\n\t\treturn true, fmt.Errorf(\"error evaluating expression: %v\", err)\n\t}\n\tif v.Kind != reflect.Bool {\n\t\tif stack.disabledErrors {\n\t\t\treturn false, nil\n\t\t}\n\t\treturn true, errors.New(\"condition expression not boolean\")\n\t}\n\tv.loadValue(LoadFullValue())\n\tif v.Unreadable != nil {\n\t\tif stack.disabledErrors {\n\t\t\treturn false, nil\n\t\t}\n\t\treturn true, fmt.Errorf(\"condition expression unreadable: %v\", v.Unreadable)\n\t}\n\treturn constant.BoolVal(v.Value), nil\n}\n\n// NoBreakpointError is returned when trying to","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/breakpoints.go#L497-L533","documentation":"Wrapped by evalBreakpointCondition (pkg/proc/breakpoints.go:515) when the AST expression of a conditional breakpoint fails during evaluation at a breakpoint hit (scope creation or compilation succeeded, but stack.eval/stack.result returned an error). Common inner causes: unreadable variables, out-of-scope variables, nil dereference, function-call evaluation errors. The breakpoint is then recorded as hit-with-error (CondError) and the condition is treated as not satisfied.","triggerScenarios":"Setting a breakpoint condition (`break loc if expr` or Condition on rpc2/DAP) whose expression cannot be evaluated at the hit point: variable not in scope at that line, nil pointer in the expression, unreadable memory, unsupported call expressions, or errors from evalop.CompileAST-propagated evaluation.","commonSituations":"Condition referencing a variable declared later in the function or only in another branch, condition on a breakpoint hit in a frame where the variable was optimized out, evaluating map/chan/func values unsupported for printing, stale conditions after code changes shift lines.","solutions":["Read the inner error after 'error evaluating expression:' — it names the failing sub-expression (undefined symbol, unreadable, etc.) and fix the condition accordingly.","Verify the variable exists and is in scope at the breakpoint location (`print var` at that breakpoint); move the breakpoint to a line where the variable is live.","Simplify the condition — avoid function calls, nil dereferences, and unsupported types; precompute into a local variable if possible.","Note that optimized Go code may make variables unreadable; rebuild with -gcflags='all=-N -l' for reliable condition evaluation."],"exampleFix":"// before: condition evaluated where x may be out of scope or nil\nbreak main.handler if x.Value == 42\n\n// after: guard against nil / move breakpoint to a line where x is in scope\nbreak main.handler if x != nil && x.Value == 42","handlingStrategy":"try-catch","validationCode":"// Before relying on a condition, evaluate it interactively at the breakpoint:\n// dlv> break main.handler\n// dlv> continue\n// dlv> print x            // is the variable in scope and readable?\n// dlv> condition 1 x != nil && x.Value == 42","typeGuard":null,"tryCatchPattern":"// Caller-side (e.g. rpc2 client) handling:\n_, err := client.Condition(bpID, \"x.Value == 42\")\n// On hit, inspect breakpoint state / ConditionReturn instead of assuming success:\nif st.CondError != nil && strings.Contains(st.CondError.Error(), \"error evaluating expression\") {\n    // fix the condition expression, do not retry blindly\n}","preventionTips":["Test every breakpoint condition with `print` at the breakpoint location before trusting it.","Write nil-safe conditions (x != nil && ...) for pointer chains.","Build with -gcflags='all=-N -l' so variables are not optimized out of conditions.","Keep conditions in sync with code changes; re-verify after edits shift lines.","Avoid function calls and unsupported types (map/chan/func values) in conditions."],"tags":["go","debugging","breakpoints","expression-evaluation","conditional-breakpoint"],"backgroundTag":"breakpoint-condition-evaluation-failed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}