zed-industries/zed · error

Could not resolve task variables within a debug scenario

Error message

Could not resolve task variables within a debug scenario

What it means

A debug scenario's `build` entry is resolved from a task template: `task_template.resolve_task("debug-build-task", &task_context)` substitutes template variables against the task context; if any variable cannot be resolved it returns None and the debug session aborts with this error (running.rs:1143). The error is about variable substitution inside the build task, not about the debug config itself.

Solutions

  1. Open the referenced build task template and replace unsupported variables with concrete values or supported ones ($ZED_WORKTREE_ROOT, $ZED_FILE, $ZED_ROW).
  2. Run the same task standalone (task runner) to see which variable fails to substitute — the task UI shows the unresolved template.
  3. Start the debug session from a context that provides the needed values (open the target file in the right worktree) before invoking the scenario.

Example fix

// before (build task template — unresolvable in debug context)
[
  { "label": "build", "command": "make build TARGET=$MY_CUSTOM_VAR", "use_new_terminal": true }
]

// after
[
  { "label": "build", "command": "make build", "cwd": "$ZED_WORKTREE_ROOT", "use_new_terminal": true }
]
Defensive patterns

Strategy: validation

Validate before calling

// dry-run variable resolution before launching the debug session
let resolved = task_template.resolve_task("debug-build-task", &task_context);
if resolved.is_none() {
    return Err(anyhow!("build task template has variables the current context cannot resolve"));
}

Try / catch

On failure, fall back to showing the raw template with unresolvable variables highlighted (run the same task standalone in the task runner) instead of a bare bail.

Prevention

When it happens

Trigger: A build task template referencing variables the debug task context does not provide — file-relative variables when no file context exists, custom/user variables, or a variable name that is not defined; also when the resolved context (worktree, active item) differs from what the template assumes.

Common situations: Running a debug scenario from a context with no open file; templates copied from tasks.json that use program-specific variables; variable renames after a Zed update; multi-worktree setups where the template assumes the wrong worktree root.

Related errors


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/15a742145d902832. Report an issue: GitHub.

Appendix: source

Thrown at crates/debugger_ui/src/session/running.rs:1143

                        let task = task_store.update(cx, |this, cx| {
                            this.task_inventory().map(|inventory| {
                                inventory.read(cx).task_template_by_label(
                                    buffer,
                                    worktree_id,
                                    label,
                                    cx,
                                )
                            })
                        })?;
                        let task = match task {
                            Some(task) => task.await,
                            None => None,
                        }.with_context(|| format!("Couldn't find task template for {build:?}"))?;
                        (task, None)
                    }
                };
                let Some(mut task) = task_template.resolve_task("debug-build-task", &task_context) else {
                    anyhow::bail!("Could not resolve task variables within a debug scenario");
                };

                let locator_name = if let Some(locator_name) = locator_name {
                    extra_config = config.clone();
                    debug_assert!(!config_is_valid);
                    Some(locator_name)
                } else if !config_is_valid {
                    let task = dap_store
                        .update(cx, |this, cx| {
                            this.debug_scenario_for_build_task(
                                task.original_task().clone(),
                                adapter.clone().into(),
                                task.display_label().to_owned().into(),
                                cx,
                            )

                        });
                    if let Ok(t) = task {

View on GitHub (pinned to f4178619ac)