Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### CLI
* Add `completion install`, `uninstall`, and `status` subcommands ([#4581](https://github.com/databricks/cli/pull/4581))
* Improve `auth token` error formatting for easier copy-paste of login commands
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include a link to the PR here


### Bundles
* Added support for git_source and git_repository for Apps ([#4538](https://github.com/databricks/cli/pull/4538))
Expand Down
8 changes: 7 additions & 1 deletion acceptance/cmd/auth/token/output.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@

>>> [CLI] auth token --host [DATABRICKS_URL]
Error: cache: databricks OAuth is not configured for this host. Try logging in again with `databricks auth login --host [DATABRICKS_URL]` before retrying. If this fails, please report this issue to the Databricks CLI maintainers at https://github.com/databricks/cli/issues/new
Error: cache: databricks OAuth is not configured for this host.

To reauthenticate, run the following command:

$ databricks auth login --host [DATABRICKS_URL]

If this fails, please report this issue to the Databricks CLI maintainers at https://github.com/databricks/cli/issues/new

Exit code: 1
6 changes: 3 additions & 3 deletions cmd/auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

func helpfulError(ctx context.Context, profile string, persistentAuth u2m.OAuthArgument) string {
loginMsg := auth.BuildLoginCommand(ctx, profile, persistentAuth)
return fmt.Sprintf("Try logging in again with `%s` before retrying. If this fails, please report this issue to the Databricks CLI maintainers at https://github.com/databricks/cli/issues/new", loginMsg)
return fmt.Sprintf("To reauthenticate, run the following command:\n\n $ %s\n\nIf this fails, please report this issue to the Databricks CLI maintainers at https://github.com/databricks/cli/issues/new", loginMsg)
}

// profileSelectionResult represents the user's choice from the interactive
Expand Down Expand Up @@ -222,7 +222,7 @@ func loadToken(ctx context.Context, args loadTokenArgs) (*oauth2.Token, error) {
persistentAuth, err := u2m.NewPersistentAuth(ctx, allArgs...)
if err != nil {
helpMsg := helpfulError(ctx, args.profileName, oauthArgument)
return nil, fmt.Errorf("%w. %s", err, helpMsg)
return nil, fmt.Errorf("%w.\n\n%s", err, helpMsg)
}
t, err := persistentAuth.Token()
if err != nil {
Expand All @@ -242,7 +242,7 @@ func loadToken(ctx context.Context, args loadTokenArgs) (*oauth2.Token, error) {
return nil, rewrittenErr
}
helpMsg := helpfulError(ctx, args.profileName, oauthArgument)
return nil, fmt.Errorf("%w. %s", err, helpMsg)
return nil, fmt.Errorf("%w.\n\n%s", err, helpMsg)
}
return t, nil
}
Expand Down
17 changes: 11 additions & 6 deletions cmd/auth/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ func TestToken_loadToken(t *testing.T) {
u2m.WithHttpClient(&http.Client{Transport: fixtures.SliceTransport{refreshFailureInvalidResponse}}),
},
},
wantErr: "token refresh: oauth2: cannot parse json: invalid character 'N' looking for beginning of value. Try logging in again with " +
"`databricks auth login --profile active` before retrying. If this fails, please report this issue to the Databricks CLI maintainers at https://github.com/databricks/cli/issues/new",
wantErr: "token refresh: oauth2: cannot parse json: invalid character 'N' looking for beginning of value.\n\n" +
"To reauthenticate, run the following command:\n\n" +
" $ databricks auth login --profile active\n\n" +
"If this fails, please report this issue to the Databricks CLI maintainers at https://github.com/databricks/cli/issues/new",
},
{
name: "prints helpful login message on other error response",
Expand All @@ -249,8 +251,10 @@ func TestToken_loadToken(t *testing.T) {
u2m.WithHttpClient(&http.Client{Transport: fixtures.SliceTransport{refreshFailureOtherError}}),
},
},
wantErr: "token refresh: Databricks is down (error code: other_error). Try logging in again with " +
"`databricks auth login --profile active` before retrying. If this fails, please report this issue to the Databricks CLI maintainers at https://github.com/databricks/cli/issues/new",
wantErr: "token refresh: Databricks is down (error code: other_error).\n\n" +
"To reauthenticate, run the following command:\n\n" +
" $ databricks auth login --profile active\n\n" +
"If this fails, please report this issue to the Databricks CLI maintainers at https://github.com/databricks/cli/issues/new",
},
{
name: "succeeds with profile",
Expand Down Expand Up @@ -345,8 +349,9 @@ func TestToken_loadToken(t *testing.T) {
u2m.WithOAuthEndpointSupplier(&MockApiClient{}),
},
},
wantErr: "cache: databricks OAuth is not configured for this host. " +
"Try logging in again with `databricks auth login --host https://nonexistent` before retrying. " +
wantErr: "cache: databricks OAuth is not configured for this host.\n\n" +
"To reauthenticate, run the following command:\n\n" +
" $ databricks auth login --host https://nonexistent\n\n" +
"If this fails, please report this issue to the Databricks CLI maintainers at https://github.com/databricks/cli/issues/new",
},
{
Expand Down