diff --git a/.nextchanges/cli/auth-token-unauthenticated.md b/.nextchanges/cli/auth-token-unauthenticated.md new file mode 100644 index 00000000000..d51c60c2639 --- /dev/null +++ b/.nextchanges/cli/auth-token-unauthenticated.md @@ -0,0 +1 @@ +* Return `UNAUTHENTICATED` instead of `INVALID_REFRESH_TOKEN` when `databricks auth token --output json` cannot refresh a cached U2M token. ([#6731](https://github.com/databricks/cli/pull/6731)) diff --git a/acceptance/cmd/auth/token/force-refresh-invalid-refresh-token/output.txt b/acceptance/cmd/auth/token/force-refresh-invalid-refresh-token/output.txt index 250f9863bfe..d975fe88448 100644 --- a/acceptance/cmd/auth/token/force-refresh-invalid-refresh-token/output.txt +++ b/acceptance/cmd/auth/token/force-refresh-invalid-refresh-token/output.txt @@ -1,6 +1,6 @@ Error: A new access token could not be retrieved because the refresh token is invalid. To reauthenticate, run the following command: $ databricks auth login --profile test-profile { - "error_code": "INVALID_REFRESH_TOKEN", + "error_code": "UNAUTHENTICATED", "message": "A new access token could not be retrieved because the refresh token is invalid. To reauthenticate, run the following command:\n $ databricks auth login --profile test-profile" } diff --git a/cmd/auth/token.go b/cmd/auth/token.go index 09d8c2dabfe..7bf710de575 100644 --- a/cmd/auth/token.go +++ b/cmd/auth/token.go @@ -25,7 +25,7 @@ import ( "golang.org/x/oauth2" ) -const invalidRefreshTokenErrorCode = "INVALID_REFRESH_TOKEN" +const unauthenticatedErrorCode = "UNAUTHENTICATED" type tokenErrorOutput struct { ErrorCode string `json:"error_code"` @@ -117,7 +117,7 @@ func writeTokenErrorOutput(w io.Writer, err error) error { encoder := json.NewEncoder(w) encoder.SetIndent("", " ") return encoder.Encode(tokenErrorOutput{ - ErrorCode: invalidRefreshTokenErrorCode, + ErrorCode: unauthenticatedErrorCode, Message: err.Error(), }) } diff --git a/cmd/auth/token_test.go b/cmd/auth/token_test.go index 18022d8ff5d..e37e7cdc01b 100644 --- a/cmd/auth/token_test.go +++ b/cmd/auth/token_test.go @@ -962,6 +962,6 @@ func TestWriteTokenErrorOutput(t *testing.T) { var got tokenErrorOutput assert.NoError(t, json.Unmarshal(buf.Bytes(), &got)) - assert.Equal(t, invalidRefreshTokenErrorCode, got.ErrorCode) + assert.Equal(t, unauthenticatedErrorCode, got.ErrorCode) assert.Equal(t, "refresh token is invalid", got.Message) }