Skip to content

Commit

Permalink
Fix error message on invalid users
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Oct 24, 2024
1 parent 32dda66 commit ae4bee4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions private/buf/cmd/buf/command/registry/whoami/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ func run(
user := currentUserResponse.Msg.User
if user == nil {
return fmt.Errorf(
`No valid user found for login credentials. Run %q to refresh your credentials. If you have %s environment variable set, ensure that the token is valid.`,
loginCommand,
`No user is logged in to %s. Run %q to refresh your credentials. If you have the %s environment variable set, ensure that the token is valid.`,
remote,
loginCommandForRemote(remote),
bufconnect.TokenEnvKey,
)
}
Expand All @@ -127,3 +128,12 @@ func run(
}
return nil
}

// loginCommandForRemote returns the login command for the given remote,
// the default remote is excluded in the command.
func loginCommandForRemote(remote string) string {
if remote == bufconnect.DefaultRemote {
return loginCommand
}
return fmt.Sprintf("%s %s", loginCommand, remote)
}

0 comments on commit ae4bee4

Please sign in to comment.