Skip to content

Commit

Permalink
Make cleaner error message for no config profile
Browse files Browse the repository at this point in the history
Fixes #484
  • Loading branch information
nfx committed Feb 10, 2021
1 parent da780ef commit 093d1df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,14 @@ func (c *DatabricksClient) configureFromDatabricksCfg() (func(r *http.Request) e
return nil, err
}
if c.Profile == "" {
log.Printf("[INFO] Using DEFAULT profile from ~/.databrickscfg")
log.Printf("[INFO] Using DEFAULT profile from %s", configFile)
c.Profile = "DEFAULT"
}
dbcli := cfg.Section(c.Profile)
if len(dbcli.Keys()) == 0 {
// here we meet a heavy user of Databricks CLI
return nil, fmt.Errorf("%s has no %s profile configured", configFile, c.Profile)
}
c.Host = dbcli.Key("host").String()
if c.Host == "" {
return nil, fmt.Errorf("config file %s is corrupt: cannot find host in %s profile",
Expand Down
5 changes: 5 additions & 0 deletions common/testdata/corrupt/.databrickscfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[nohost]
token = PT0+IC9kZXYvdXJhbmRvbSA8PT0KYFZ

[notoken]
host = https://dbc-XXXXXXXX-YYYY.cloud.databricks.com/
6 changes: 6 additions & 0 deletions provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ func TestProviderConfigurationOptions(t *testing.T) {
assertHost: "",
assertToken: "",
},
{
env: map[string]string{
"HOME": "../common/testdata/corrupt",
},
assertError: "../common/testdata/corrupt/.databrickscfg has no DEFAULT profile configured",
},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("config:%v env:%v", tt.rawConfig(), tt.env), func(t *testing.T) {
Expand Down

0 comments on commit 093d1df

Please sign in to comment.