Skip to content

fix(auth): surface 'No token' dispatch failure as AuthError::NoToken#3721

Open
sandikodev wants to merge 1 commit intoaws:mainfrom
sandikodev:fix/auth-error-no-token
Open

fix(auth): surface 'No token' dispatch failure as AuthError::NoToken#3721
sandikodev wants to merge 1 commit intoaws:mainfrom
sandikodev:fix/auth-error-no-token

Conversation

@sandikodev
Copy link
Copy Markdown

@sandikodev sandikodev commented Apr 4, 2026

Issue

Closes #3173

Problem

When a session expires mid-chat, the AWS SDK returns a DispatchFailure with "No token" in the error chain. This was converted to ChatError::Client and displayed as an opaque multi-line error:

Amazon Q is having trouble responding right now:
   0: Failed to send the request: dispatch failure (other): No token
   1: dispatch failure (other): No token
   2: dispatch failure
   3: other
   4: No token

The handler for ChatError::Auth(AuthError::NoToken) already exists and displays a clear, actionable message — but it was never reached because the error was wrapped as ChatError::Client.

Fix

Add is_no_token_error() which walks the error source chain to detect the "No token" string. In From<ApiClientError> for ChatError, check for this condition and convert to ChatError::Auth(AuthError::NoToken) so the existing handler is triggered, showing:

Authentication Error

Your login session has expired. Please log in again using:

    q login

Testing

# Run the targeted tests
cargo test -p chat_cli is_no_token_error

# Run the full test suite to check for regressions
cargo test -p chat_cli

Four tests cover all cases:

  1. detects_auth_no_tokenApiClientError::AuthError(AuthError::NoToken) is detected
  2. ignores_unrelated_errors — unrelated errors (e.g. DefaultModelNotFound) are not detected
  3. from_api_client_error_converts_no_token_to_auth_errorFrom conversion produces ChatError::Auth(AuthError::NoToken)
  4. from_api_client_error_keeps_other_errors_as_client — other errors remain as ChatError::Client

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

When a session expires mid-chat, the AWS SDK returns a dispatch failure
with 'No token' in the error chain. This was converted to ChatError::Client
and displayed as an opaque multi-line error instead of the clear
'Your session has expired. Run q login' message.

Add is_no_token_error() to walk the error source chain and detect this
case, converting it to ChatError::Auth(AuthError::NoToken) so the
existing handler in handle_chat_error displays the actionable message.

Fixes aws#3173
@sandikodev sandikodev force-pushed the fix/auth-error-no-token branch from ad6e6bf to aec6f6c Compare April 4, 2026 16:00
@sandikodev
Copy link
Copy Markdown
Author

Update (amended commit): Tests were added after initial submission covering four cases:

  1. ApiClientError::AuthError(AuthError::NoToken) is detected by is_no_token_error
  2. Unrelated errors (e.g. DefaultModelNotFound) are not detected
  3. From<ApiClientError> converts a No-token error to ChatError::Auth(AuthError::NoToken)
  4. From<ApiClientError> keeps other errors as ChatError::Client

This ensures the error chain walking logic is correct and the From conversion behaves as expected in both the bug case and the normal case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Opaque error when login expires

1 participant