Suggest "did you mean ...?" for unknown key lookups and variable references - #6208
Open
Sankalp-Mittal wants to merge 6 commits into
Open
Suggest "did you mean ...?" for unknown key lookups and variable references#6208Sankalp-Mittal wants to merge 6 commits into
Sankalp-Mittal wants to merge 6 commits into
Conversation
Collaborator
Integration test reportCommit: eea6c6b
8 interesting tests: 4 RECOVERED, 4 SKIP
Top 6 slowest tests (at least 2 minutes):
|
Sankalp-Mittal
marked this pull request as ready for review
August 10, 2026 10:30
Contributor
Approval status: pending
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
When a key lookup on a
dyn.Valuefails, 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 aMappingwithinmaxSuggestionDistance(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.noSuchKeyErrornow carries the suggestions, computed at the point of failure inpathComponent.visitwhere the parent map is in scope, and renders them in itsError(). Because variable interpolation inlibs/dyn/dynvarrewrites the not-found message (and discards the original error), it re-attaches the hint via the new exporteddyn.DidYouMeanSuffix(err).Scope
Because the hint is attached at the generic
dynkey-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 namesIt also benefits any other
dyn.GetByPathcaller 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 nonoSuchKeyError— 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 barereference 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 genericdynlayer 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 forlevenshteinDistance,suggestKeys(distance threshold, ordering, empty map),didYouMean, andDidYouMeanSuffix.libs/dyn/visit_get_test.go— a close key produces a suggestion; a far-off key produces none.libs/dyn/dynvar/resolve_test.go—TestResolveNotFoundSuggestsCloseKeyasserts the hint flows through variable interpolation.