Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: enrich the notLoggedInMessage error message with the full path to the coder #17715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cli/logout_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli_test

import (
"fmt"
"os"
"runtime"
"testing"
Expand Down Expand Up @@ -89,10 +90,14 @@ func TestLogout(t *testing.T) {
logout.Stdin = pty.Input()
logout.Stdout = pty.Output()

executable, err := os.Executable()
require.NoError(t, err)
require.NotEqual(t, "", executable)

go func() {
defer close(logoutChan)
err := logout.Run()
assert.ErrorContains(t, err, "You are not logged in. Try logging in using 'coder login <url>'.")
err = logout.Run()
assert.Contains(t, err.Error(), fmt.Sprintf("Try logging in using '%s login <url>'.", executable))
}()

<-logoutChan
Expand Down
8 changes: 6 additions & 2 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const (
varDisableDirect = "disable-direct-connections"
varDisableNetworkTelemetry = "disable-network-telemetry"

notLoggedInMessage = "You are not logged in. Try logging in using 'coder login <url>'."
notLoggedInMessage = "You are not logged in. Try logging in using '%s login <url>'."

envNoVersionCheck = "CODER_NO_VERSION_WARNING"
envNoFeatureWarning = "CODER_NO_FEATURE_WARNING"
Expand Down Expand Up @@ -534,7 +534,11 @@ func (r *RootCmd) InitClient(client *codersdk.Client) serpent.MiddlewareFunc {
rawURL, err := conf.URL().Read()
// If the configuration files are absent, the user is logged out
if os.IsNotExist(err) {
return xerrors.New(notLoggedInMessage)
binPath, err := os.Executable()
if err != nil {
binPath = "coder"
}
return xerrors.Errorf(notLoggedInMessage, binPath)
}
if err != nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions cli/userlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -69,9 +71,12 @@ func TestUserList(t *testing.T) {
t.Run("NoURLFileErrorHasHelperText", func(t *testing.T) {
t.Parallel()

executable, err := os.Executable()
require.NoError(t, err)

inv, _ := clitest.New(t, "users", "list")
err := inv.Run()
require.Contains(t, err.Error(), "Try logging in using 'coder login <url>'.")
err = inv.Run()
require.Contains(t, err.Error(), fmt.Sprintf("Try logging in using '%s login <url>'.", executable))
})
t.Run("SessionAuthErrorHasHelperText", func(t *testing.T) {
t.Parallel()
Expand Down
Loading