Skip to content

Commit bb05c83

Browse files
committed
fix: friendlier error for unauthenticated user
When a user is not logged, and never logged in the error message is not that actionable. It says the user thy should login but now how to do it. As reported by @ecv we can do a lot better. There is another error that looks similar but exposes the right command to run to login. This commit uses the same approach. This is the current one in main ``` panic: failed to get token source: no active user set. Please login first goroutine 1 [running]: go.datum.net/datumctl/internal/cmd.RootCmd() /home/gianarb/git/datum/datumctl/internal/cmd/root.go:38 +0xc3a main.main() /home/gianarb/git/datum/datumctl/main.go:15 +0x32 exit status 2 ``` Here what user will get with this commit: ``` panic: failed to get token source: no active user set. Please login first using 'datumctl auth login' goroutine 1 [running]: go.datum.net/datumctl/internal/cmd.RootCmd() /home/gianarb/git/datum/datumctl/internal/cmd/root.go:38 +0xc3a main.main() /home/gianarb/git/datum/datumctl/main.go:15 +0x32 exit status 2 ``` NOTE: There is another race condition related to when we run authentication and it prevents the `help` command to get printed to the user. But I am working at it in another PR
1 parent 2631a7a commit bb05c83

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

internal/authutil/credentials.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const ActiveUserKey = "active_user"
2424
const KnownUsersKey = "known_users"
2525

2626
// ErrNoActiveUser indicates that no active user is set in the keyring.
27-
var ErrNoActiveUser = errors.New("no active user set. Please login first")
27+
var ErrNoActiveUser = errors.New("You haven't authenticated with Datum Cloud yet. Please login first using 'datumctl auth login' and retry the command.")
2828

2929
// StoredCredentials holds all necessary information for a single authenticated session.
3030
type StoredCredentials struct {

internal/cmd/auth/get_token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func runGetToken(cmd *cobra.Command, args []string) error {
5151
tokenSource, err := authutil.GetTokenSource(ctx)
5252
if err != nil {
5353
if errors.Is(err, authutil.ErrNoActiveUser) {
54-
return errors.New("no active user found in keyring. Please login first using 'datumctl auth login'")
54+
return err
5555
}
5656
return fmt.Errorf("failed to get token source: %w", err)
5757
}

0 commit comments

Comments
 (0)