Skip to content

Commit 6dda24e

Browse files
authored
Improve error message for host mismatch between bundle and profile used (#3100)
## Changes Improve error message for host mismatch between bundle and profile used ## Why Now we make the wording a bit more explicit and include suggestion which config profile can be used. ## Tests Covered by existing acceptance tests <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 79d0f89 commit 6dda24e

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### CLI
1010

1111
### Bundles
12+
* Improve error message for host mismatch between bundle and profile used ([#3100](https://github.com/databricks/cli/pull/3100))
1213
* Remove support for deprecated `experimental/pydabs` config, use `experimental/python` instead. See [Configuration in Python
1314
](https://docs.databricks.com/dev-tools/bundles/python). ([#3102](https://github.com/databricks/cli/pull/3102))
1415

acceptance/auth/bundle_and_profile/output.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Exit code: 1
1919

2020
=== Inside the bundle, target and not matching profile
2121
>>> errcode [CLI] current-user me -t dev -p profile_name
22-
Error: cannot resolve bundle auth configuration: config host mismatch: profile uses host https://non-existing-subdomain.databricks.com, but CLI configured to use [DATABRICKS_TARGET]
22+
Error: cannot resolve bundle auth configuration: the host in the profile (https://non-existing-subdomain.databricks.com) doesn’t match the host configured in the bundle ([DATABRICKS_TARGET]). The profile "DEFAULT" has host="[DATABRICKS_TARGET]" that matches host in the bundle. To select it, pass "-p DEFAULT"
2323

2424
Exit code: 1
2525

@@ -47,7 +47,7 @@ Validation OK!
4747

4848
=== Bundle commands load bundle configuration with -p flag, validation not OK (profile host don't match bundle host)
4949
>>> errcode [CLI] bundle validate -p profile_name
50-
Error: cannot resolve bundle auth configuration: config host mismatch: profile uses host https://non-existing-subdomain.databricks.com, but CLI configured to use [DATABRICKS_TARGET]
50+
Error: cannot resolve bundle auth configuration: the host in the profile (https://non-existing-subdomain.databricks.com) doesn’t match the host configured in the bundle ([DATABRICKS_TARGET]). The profile "DEFAULT" has host="[DATABRICKS_TARGET]" that matches host in the bundle. To select it, pass "-p DEFAULT"
5151

5252
Name: test-auth
5353
Target: dev
@@ -71,7 +71,7 @@ Validation OK!
7171

7272
=== Bundle commands load bundle configuration with -t and -p flag, validation not OK (profile host don't match bundle host)
7373
>>> errcode [CLI] bundle validate -t prod -p DEFAULT
74-
Error: cannot resolve bundle auth configuration: config host mismatch: profile uses host [DATABRICKS_TARGET], but CLI configured to use https://bar.com
74+
Error: cannot resolve bundle auth configuration: the host in the profile ([DATABRICKS_TARGET]) doesn’t match the host configured in the bundle (https://bar.com)
7575

7676
Name: test-auth
7777
Target: prod

bundle/config/workspace_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func TestWorkspaceVerifyProfileForHost(t *testing.T) {
114114
require.NoError(t, err)
115115

116116
_, err = w.Client()
117-
assert.ErrorContains(t, err, "config host mismatch")
117+
assert.ErrorContains(t, err, "doesn’t match the host configured in the bundle")
118118
})
119119

120120
t.Run("custom config file with match", func(t *testing.T) {
@@ -146,6 +146,6 @@ func TestWorkspaceVerifyProfileForHost(t *testing.T) {
146146

147147
t.Setenv("DATABRICKS_CONFIG_FILE", filepath.Join(home, "customcfg"))
148148
_, err = w.Client()
149-
assert.ErrorContains(t, err, "config host mismatch")
149+
assert.ErrorContains(t, err, "doesn’t match the host configured in the bundle")
150150
})
151151
}

cmd/root/bundle_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestBundleConfigureWithMismatchedProfile(t *testing.T) {
109109
require.NoError(t, err)
110110

111111
err = setupWithHost(t, cmd, "https://x.com")
112-
assert.ErrorContains(t, err, "config host mismatch: profile uses host https://a.com, but CLI configured to use https://x.com")
112+
assert.ErrorContains(t, err, "the host in the profile (https://a.com) doesn’t match the host configured in the bundle (https://x.com)")
113113
}
114114

115115
func TestBundleConfigureWithCorrectProfile(t *testing.T) {
@@ -132,7 +132,7 @@ func TestBundleConfigureWithMismatchedProfileEnvVariable(t *testing.T) {
132132
cmd := emptyCommand(t)
133133

134134
err := setupWithHost(t, cmd, "https://x.com")
135-
assert.ErrorContains(t, err, "config host mismatch: profile uses host https://a.com, but CLI configured to use https://x.com")
135+
assert.ErrorContains(t, err, "the host in the profile (https://a.com) doesn’t match the host configured in the bundle (https://x.com)")
136136
}
137137

138138
func TestBundleConfigureWithProfileFlagAndEnvVariable(t *testing.T) {

libs/databrickscfg/ops.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,16 @@ func ValidateConfigAndProfileHost(cfg *config.Config, profile string) error {
148148

149149
hostFromProfile := normalizeHost(match.Key("host").Value())
150150
if hostFromProfile != "" && host != "" && hostFromProfile != host {
151-
return fmt.Errorf("config host mismatch: profile uses host %s, but CLI configured to use %s", hostFromProfile, host)
151+
// Try to find if there's a profile which uses the same host as the bundle and suggest in error message
152+
match, err = findMatchingProfile(configFile, func(s *ini.Section) bool {
153+
return normalizeHost(s.Key("host").Value()) == host
154+
})
155+
if err == nil && match != nil {
156+
profileName := match.Name()
157+
return fmt.Errorf("the host in the profile (%s) doesn’t match the host configured in the bundle (%s). The profile \"%s\" has host=\"%s\" that matches host in the bundle. To select it, pass \"-p %s\"", hostFromProfile, host, profileName, host, profileName)
158+
}
159+
160+
return fmt.Errorf("the host in the profile (%s) doesn’t match the host configured in the bundle (%s)", hostFromProfile, host)
152161
}
153162

154163
return nil

0 commit comments

Comments
 (0)