Skip to content

Suggest "did you mean ...?" for unknown key lookups and variable references - #6208

Open
Sankalp-Mittal wants to merge 6 commits into
mainfrom
sankalp-mittal/did-you-mean-variable-interpolation
Open

Suggest "did you mean ...?" for unknown key lookups and variable references#6208
Sankalp-Mittal wants to merge 6 commits into
mainfrom
sankalp-mittal/did-you-mean-variable-interpolation

Conversation

@Sankalp-Mittal

@Sankalp-Mittal Sankalp-Mittal commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Changes

When a key lookup on a dyn.Value fails, the error now appends a "did you mean" hint listing the closest existing keys (edit distance ≤ 2), ordered by proximity:

  • key not found at "baz", did you mean "bar"?
  • reference does not exist: ${hst}, did you mean "host"?

The suggestion logic lives in a new libs/dyn/suggest.go:

  • levenshteinDistance — edit distance between two strings.
  • suggestKeys — keys of a Mapping within maxSuggestionDistance (2) of the missing key, sorted by increasing distance (ties keep insertion order).
  • didYouMean — formats the clause (, did you mean "x"? for one candidate, , did you mean one of: "x", "y"? for several); empty when there are no matches.

noSuchKeyError now carries the suggestions, computed at the point of failure in pathComponent.visit where the parent map is in scope, and renders them in its Error(). Because variable interpolation in libs/dyn/dynvar rewrites the not-found message (and discards the original error), it re-attaches the hint via the new exported dyn.DidYouMeanSuffix(err).

Scope

Because the hint is attached at the generic dyn key-lookup layer, it applies to all references that resolve via a key lookup, not only ${var.*}. A typo in the leaf of any resolvable path gets suggestions drawn from that level's siblings:

  • ${var.my_catlog} → suggests other variable names
  • ${workspace.rooot_path} / ${bundle.naem} → suggests sibling config fields
  • ${resources.jobs.nightlyy} → suggests sibling resource names

It also benefits any other dyn.GetByPath caller in the codebase. The one case it does not cover is a wrong top-level prefix (e.g. ${wrkspace.host}): unrecognized prefixes are skipped during resolution and never reach a key lookup, so no noSuchKeyError — and no suggestion — is produced.

Why

A mistyped variable reference in databricks.yml (e.g. ${var.my_catlog} instead of ${var.my_catalog}) previously failed with a bare reference does not exist: ${var.my_catlog} and no hint, even though the CLI knows every valid key at the point of failure. The CLI already offers this for mistyped command-line flags; this brings the same guidance to key lookups and variable interpolation. Attaching the hint at the generic dyn layer means every not-found key lookup benefits, not just variable resolution.

Suggestions are shown only when a candidate is within edit distance 2; otherwise the error is unchanged, so unrelated typos don't produce noisy or misleading hints.

Tests

  • libs/dyn/suggest_test.go — unit tests for levenshteinDistance, suggestKeys (distance threshold, ordering, empty map), didYouMean, and DidYouMeanSuffix.
  • libs/dyn/visit_get_test.go — a close key produces a suggestion; a far-off key produces none.
  • libs/dyn/dynvar/resolve_test.goTestResolveNotFoundSuggestsCloseKey asserts the hint flows through variable interpolation.

@Sankalp-Mittal Sankalp-Mittal changed the title Sankalp mittal/did you mean variable interpolation Suggest "did you mean ...?" for unknown key lookups and variable references Aug 10, 2026
@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Integration test report

Commit: eea6c6b

Run: 31476432241

Env 💚​RECOVERED 🙈​SKIP ✅​pass 🙈​skip Time
💚​ aws linux 4 4 294 1124 8:48
💚​ aws windows 4 4 296 1122 6:32
💚​ azure linux 4 4 293 1124 6:41
💚​ azure windows 4 4 295 1122 6:32
💚​ gcp linux 1 5 294 1124 7:03
💚​ gcp windows 1 5 296 1122 9:08
8 interesting tests: 4 RECOVERED, 4 SKIP
Test Name aws linux aws windows azure linux azure windows gcp linux gcp windows
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
🙈​ TestAccept/bundle/invariant/no_drift 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_endpoints/drift/recreated_same_name 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_indexes/recreate/embedding_dimension 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/ssh/connection 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
💚​ TestFetchRepositoryInfoAPI_FromRepo 💚​R 💚​R 💚​R 💚​R 🙈​S 🙈​S
💚​ TestFetchRepositoryInfoAPI_FromRepo/root 💚​R 💚​R 💚​R 💚​R
💚​ TestFetchRepositoryInfoAPI_FromRepo/subdir 💚​R 💚​R 💚​R 💚​R
Top 6 slowest tests (at least 2 minutes):
duration env testname
8:59 gcp windows TestAccept
6:24 aws windows TestAccept
6:24 azure windows TestAccept
3:09 aws linux TestAccept
3:08 gcp linux TestAccept
3:01 azure linux TestAccept

@Sankalp-Mittal
Sankalp-Mittal marked this pull request as ready for review August 10, 2026 10:30
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Approval status: pending

/acceptance/bundle/ - needs approval

4 files changed
Suggested: @pietern
Also eligible: @denik, @andrewnester, @janniklasrose, @lennartkats-db, @anton-107, @shreyas-goenka

General files (require maintainer)

7 files changed
Based on git history:

  • @pietern -- recent work in libs/dyn/, libs/dyn/dynvar/, .nextchanges/cli/

Any maintainer (@andrewnester, @anton-107, @denik, @pietern, @shreyas-goenka, @simonfaltum, @renaudhartert-db, @janniklasrose, @lennartkats-db, @rugpanov, @rclarey) can approve all areas.
See OWNERS for ownership rules.

@Sankalp-Mittal
Sankalp-Mittal requested a review from pietern August 12, 2026 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants