Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix: underline each variable name individually in template error hints (#2028)

Maximilian Roosaefb33321932
diff --git a/src/config/expansion.rs b/src/config/expansion.rs
index 0c390c985..7afa0aeda 100644
--- a/src/config/expansion.rs
+++ b/src/config/expansion.rs
@@ -237,10 +237,15 @@ impl std::fmt::Display for TemplateExpandError {
parts.push(format_with_gutter(line, None));
}
if !self.available_vars.is_empty() {
+ let underlined_vars: Vec<String> = self
+ .available_vars
+ .iter()
+ .map(|v| cformat!("<underline>{}</>", v))
+ .collect();
parts.push(
hint_message(cformat!(
- "Available variables: <underline>{}</>",
- self.available_vars.join(", ")
+ "Available variables: {}",
+ underlined_vars.join(", ")
))
.to_string(),
);
@@ -770,7 +775,7 @@ mod tests {
assert_snapshot!(err, @"
✗ Failed to expand test: undefined value @ line 1
  echo {{ target }}
- ↳ Available variables: branch, remote
+ ↳ Available variables: branch, remote
");
}
diff --git a/tests/snapshots/integration__integration_tests__eval__eval_template_error.snap b/tests/snapshots/integration__integration_tests__eval__eval_template_error.snap
index bbff5d3d1..f350814ac 100644
--- a/tests/snapshots/integration__integration_tests__eval__eval_template_error.snap
+++ b/tests/snapshots/integration__integration_tests__eval__eval_template_error.snap
@@ -47,4 +47,4 @@ exit_code: 1
----- stderr -----
✗ Failed to expand eval: undefined value @ line 1
  {{ undefined_var }}
-↳ Available variables: branch, commit, cwd, default_branch, main_worktree, main_worktree_path, primary_worktree_path, remote, remote_url, repo, repo_path, repo_root, short_commit, upstream, worktree, worktree_name, worktree_path
+↳ Available variables: branch, commit, cwd, default_branch, main_worktree, main_worktree_path, primary_worktree_path, remote, remote_url, repo, repo_path, repo_root, short_commit, upstream, worktree, worktree_name, worktree_path
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_upstream_template.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_upstream_template.snap
index 68bad4277..e17d20473 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_upstream_template.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_upstream_template.snap
@@ -49,4 +49,4 @@ exit_code: 1
▲ Project config has deprecated settings. Run wt config show for details or wt config update to apply updates
✗ Failed to expand project pre-start hook: undefined value @ line 1
  echo 'Upstream: {{ upstream }}' > upstream.txt
-↳ Available variables: base, base_worktree_path, branch, commit, cwd, default_branch, hook_type, main_worktree, main_worktree_path, primary_worktree_path, remote, remote_url, repo, repo_path, repo_root, short_commit, worktree, worktree_name, worktree_path
+↳ Available variables: base, base_worktree_path, branch, commit, cwd, default_branch, hook_type, main_worktree, main_worktree_path, primary_worktree_path, remote, remote_url, repo, repo_path, repo_root, short_commit, worktree, worktree_name, worktree_path
diff --git a/tests/snapshots/integration__integration_tests__step_relocate__relocate_template_error.snap b/tests/snapshots/integration__integration_tests__step_relocate__relocate_template_error.snap
index da78320f7..b6cad0791 100644
--- a/tests/snapshots/integration__integration_tests__step_relocate__relocate_template_error.snap
+++ b/tests/snapshots/integration__integration_tests__step_relocate__relocate_template_error.snap
@@ -48,5 +48,5 @@ exit_code: 0
▲ Skipping feature due to template error:
✗ Failed to expand worktree-path: undefined value @ line 1
  {{ nonexistent_variable }}
-↳ Available variables: branch, main_worktree, repo, repo_path
+↳ Available variables: branch, main_worktree, repo, repo_path
○ No relocations performed; 1 skipped due to template error