diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index fad1499ad6..1f53bf3145 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -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 ### Bundles * Added support for git_source and git_repository for Apps ([#4538](https://github.com/databricks/cli/pull/4538)) diff --git a/acceptance/cmd/auth/token/output.txt b/acceptance/cmd/auth/token/output.txt index 9299dfe871..c2d914ede8 100644 --- a/acceptance/cmd/auth/token/output.txt +++ b/acceptance/cmd/auth/token/output.txt @@ -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 diff --git a/cmd/auth/token.go b/cmd/auth/token.go index 466db569a8..f402399036 100644 --- a/cmd/auth/token.go +++ b/cmd/auth/token.go @@ -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 @@ -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 { @@ -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 } diff --git a/cmd/auth/token_test.go b/cmd/auth/token_test.go index 3ec29fd515..36140f9adf 100644 --- a/cmd/auth/token_test.go +++ b/cmd/auth/token_test.go @@ -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", @@ -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", @@ -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", }, {