Repository navigation
feat: improve AWS credential errors - #918
Conversation
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit e45e486. Configure here.
f26e330 to
35494a8
Compare
The credential error is short. If the SSO token of the profile is expired or not in the cache, the error gives the aws sso login advice. SSOTokenInvalid finds this for sso_session profiles, which aws configure sso writes, and for legacy sso_start_url profiles. Tests use the real SDK with real config files. Any other cause shows in the error, also for an SSO profile, except the cause from the EC2 metadata service. That cause only says that no other source had credentials. The error lists at most 5 profile names. errors.Unwrap still returns the cause. Without --profile, the profile comes from AWS_PROFILE, then AWS_DEFAULT_PROFILE, then the default profile, as in the SDK. sso.go adds SelectedProfile, SSOProfile, HasSSOConfig, and SSOTokenInvalid. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
35494a8 to
8bfaa17
Compare
|
Post-merge thought for @cchu-ld — not a blocker, just something I noticed while reading through the stack:
via LD Research 🤖 |
Requirements
Related issues
None.
Describe the solution you've provided
169.254.169.254. That text did not help the user.credential_process, still shows, because it tells what failed.errors.Unwrapstill returns the cause.aws sso login, also a profile that does not use SSO.SSOTokenInvalidfinds that case in each form that the SDK returns it:ssocreds.InvalidTokenErrorfor a legacysso_start_urlprofile, a wrappedfs.ErrNotExistfor ansso_sessionprofile with no cached token, and the textrefresh cached SSO token failedfor ansso_sessiontoken that expired. The SDK has no error type for the last case. Tests call the real SDK with real config files. Other SSO errors, for example a removed role assignment, show their cause, because a login does not fix them.--profileorAWS_PROFILE, the error ignored the profile that the SDK used. Adefaultprofile with SSO got no SSO advice. Adefaultprofile with a brokencredential_processgotno AWS profile selected, and the cause was lost.SelectedProfilereadsAWS_PROFILE, thenAWS_DEFAULT_PROFILE, then usesdefault, as the SDK does. The error then gives the advice or the cause for that profile.aws configure list-profiles.Describe alternatives you've considered
None.
Additional context
Testing:
go test ./...andgolangci-lintpass on this branch.🤖 Generated with Claude Code
Note
Overview
Improves AWS credential failure messages when
NewClientscannot resolve credentials, without changing howerrors.Is(err, ErrNoCredentials)works.User-facing text no longer appends EC2 IMDS noise (
169.254.169.254, retries); the SDK cause stays onerrors.Unwrap. Non-IMDS causes (e.g.credential_process) still surface when they explain the failure.Messages are scenario-specific: SSO profiles get
aws sso loginonly whenSSOTokenInvaliddetects a missing/expired token (newsso.gohelpers parse config forsso_session/sso_start_urland mirror SDK error shapes). Non-SSO empty profiles get “has no AWS credentials”; profile selection follows--profile,AWS_PROFILE, thenAWS_DEFAULT_PROFILE, thendefault. When nothing is selected, at most five profile names are listed plus a pointer toaws configure list-profiles.Adds broad unit/integration-style tests in
credentials_test.goandsso_test.go; existingNewClientscredential tests are updated accordingly.Reviewed by Cursor Bugbot for commit 35494a8. Bugbot is set up for automated code reviews on this repo. Configure here.