go-delve/delve · error
could not find variable %q: %v
Error message
could not find variable %q: %v
What it means
starlarkTargetObject.Attr resolves a named attribute by evaluating it as a variable expression in the debuggee via Client().EvalVariable; when the debugger cannot evaluate the expression (undefined symbol, wrong scope, optimized-out variable) the underlying error is wrapped as `could not find variable %q`.
Source
Thrown at pkg/terminal/starbind/conv.go:744
}
func (starlarkTargetObject) Truth() starlark.Bool {
return true
}
func (starlarkTargetObject) Type() string {
return "<target variables>"
}
func (tgt starlarkTargetObject) AttrNames() []string {
return nil
}
func (tgt starlarkTargetObject) Attr(name string) (starlark.Value, error) {
env := tgt.env
v, err := env.ctx.Client().EvalVariable(env.ctx.Scope(), name, env.ctx.LoadConfig())
if err != nil {
return starlark.None, fmt.Errorf("could not find variable %q: %v", name, err)
}
return env.variableValueToStarlarkValue(v, true)
}
type starlarkUnhashable struct {
}
func (starlarkUnhashable) Freeze() {
}
func (starlarkUnhashable) Hash() (uint32, error) {
return 0, errors.New("not hashable")
}
View on GitHub (pinned to a23773e6c3)
Solutions
- Verify the variable exists in the current scope (use `locals`/`print` in the CLI first)
- Qualify package variables with their package path (e.g. main.myVar)
- Switch the evaluation scope/goroutine before accessing the attribute
- Check the inner error (%v) for details like 'could not find symbol' or 'optimized out'
Example fix
# before x = tgt.counter # counter not in current frame scope # after x = tgt["main.globalCounter"] # qualified name, or # switch scope to the frame holding the local first
Defensive patterns
Strategy: try-catch
Validate before calling
# pre-check the name exists in scope via a plain evaluation before use
out = eval_in_debugger(name)
if out is None or 'could not find' in out:
fail("variable %r not in scope" % name) Try / catch
try:
v = tgt.someVar
except Exception as e:
if "could not find variable" in str(e):
v = None # or re-qualify the name and retry
else:
raise Prevention
- Confirm the variable exists in the current frame with `locals`/`print` first
- Qualify package-level names (pkg.var)
- Account for compiler optimizations removing locals
- Set the correct goroutine/scope before attribute access
When it happens
Trigger: A Starlark script accesses `target_object.someVar` where someVar is not a variable in the current evaluation scope (env.ctx.Scope()), or the name is a function/local that has been optimized out or belongs to another goroutine/frame.
Common situations: Scripts run with a scope pointing at a frame where the local no longer exists, accessing package-level names that need package qualification, or typos in variable names.
Related errors
- can not assign to %T.%q: %v
- can not assign big integer to %T.%q
- can not assign value of type %T to %T.%q
- key type not supported %T
- error setting argument %q to %s: %v
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/6eeacf3b60c38296.
Report an issue: GitHub.